@@ -3400,6 +3400,17 @@ mod simd {
3400
3400
/// Note that the `T` produced by the expression `$e` will *not* be dropped.
3401
3401
/// Semantically, its bits will be copied into a new value of type `U`, the
3402
3402
/// original `T` will be forgotten, and the value of type `U` will be returned.
3403
+ ///
3404
+ /// # Examples
3405
+ ///
3406
+ /// ```
3407
+ /// # use zerocopy::transmute;
3408
+ /// let one_dimensional: [u8; 8] = [0, 1, 2, 3, 4, 5, 6, 7];
3409
+ ///
3410
+ /// let two_dimensional: [[u8; 4]; 2] = transmute!(one_dimensional);
3411
+ ///
3412
+ /// assert_eq!(two_dimensional, [[0, 1, 2, 3], [4, 5, 6, 7]]);
3413
+ /// ```
3403
3414
#[ macro_export]
3404
3415
macro_rules! transmute {
3405
3416
( $e: expr) => { {
@@ -3455,6 +3466,17 @@ macro_rules! transmute {
3455
3466
/// The lifetime of the input type, `&T` or `&mut T`, must be the same as or
3456
3467
/// outlive the lifetime of the output type, `&U`.
3457
3468
///
3469
+ /// # Examples
3470
+ ///
3471
+ /// ```
3472
+ /// # use zerocopy::transmute_ref;
3473
+ /// let one_dimensional: [u8; 8] = [0, 1, 2, 3, 4, 5, 6, 7];
3474
+ ///
3475
+ /// let two_dimensional: &[[u8; 4]; 2] = transmute_ref!(&one_dimensional);
3476
+ ///
3477
+ /// assert_eq!(two_dimensional, &[[0, 1, 2, 3], [4, 5, 6, 7]]);
3478
+ /// ```
3479
+ ///
3458
3480
/// # Alignment increase error message
3459
3481
///
3460
3482
/// Because of limitations on macros, the error message generated when
@@ -3550,6 +3572,21 @@ macro_rules! transmute_ref {
3550
3572
/// The lifetime of the input type, `&mut T`, must be the same as or outlive the
3551
3573
/// lifetime of the output type, `&mut U`.
3552
3574
///
3575
+ /// # Examples
3576
+ ///
3577
+ /// ```
3578
+ /// # use zerocopy::transmute_mut;
3579
+ /// let mut one_dimensional: [u8; 8] = [0, 1, 2, 3, 4, 5, 6, 7];
3580
+ ///
3581
+ /// let two_dimensional: &mut [[u8; 4]; 2] = transmute_mut!(&mut one_dimensional);
3582
+ ///
3583
+ /// assert_eq!(two_dimensional, &[[0, 1, 2, 3], [4, 5, 6, 7]]);
3584
+ ///
3585
+ /// two_dimensional.reverse();
3586
+ ///
3587
+ /// assert_eq!(one_dimensional, [4, 5, 6, 7, 0, 1, 2, 3]);
3588
+ /// ```
3589
+ ///
3553
3590
/// # Alignment increase error message
3554
3591
///
3555
3592
/// Because of limitations on macros, the error message generated when
0 commit comments