Skip to content

Commit 9fe8aae

Browse files
authored
Use pseudocode to document transmute_ref (#1050)
Partially addresses #1046.
1 parent 21f81fb commit 9fe8aae

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/lib.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4418,14 +4418,27 @@ macro_rules! transmute {
44184418
/// Safely transmutes a mutable or immutable reference of one type to an
44194419
/// immutable reference of another type of the same size.
44204420
///
4421-
/// The expression `$e` must have a concrete type, `&T` or `&mut T`, where `T:
4422-
/// Sized + IntoBytes`. The `transmute_ref!` expression must also have a
4423-
/// concrete type, `&U` (`U` is inferred from the calling context), where `U:
4424-
/// Sized + FromBytes`. It must be the case that `align_of::<T>() >=
4425-
/// align_of::<U>()`.
4421+
/// This macro behaves like an invocation of this function:
4422+
///
4423+
/// ```ignore
4424+
/// const fn transmute_ref<'src, 'dst, Src, Dst>(src: &'src Src) -> &'dst Dst
4425+
/// where
4426+
/// 'src: 'dst,
4427+
/// Src: IntoBytes + NoCell,
4428+
/// Dst: FromBytes + NoCell,
4429+
/// size_of::<Src>() == size_of::<Dst>(),
4430+
/// align_of::<Src>() >= align_of::<Dst>(),
4431+
/// {
4432+
/// # /*
4433+
/// ...
4434+
/// # */
4435+
/// }
4436+
/// ```
44264437
///
4427-
/// The lifetime of the input type, `&T` or `&mut T`, must be the same as or
4428-
/// outlive the lifetime of the output type, `&U`.
4438+
/// However, unlike a function, this macro can only be invoked when the types of
4439+
/// `Src` and `Dst` are completely concrete. The types `Src` and `Dst` are
4440+
/// inferred from the calling context; they cannot be explicitly specified in
4441+
/// the macro invocation.
44294442
///
44304443
/// # Examples
44314444
///

0 commit comments

Comments
 (0)