Skip to content

Commit

Permalink
Use pseudocode to document transmute_ref
Browse files Browse the repository at this point in the history
Partially addresses #1046.
  • Loading branch information
jswrenn committed Mar 15, 2024
1 parent 730f400 commit c2a4159
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4418,14 +4418,25 @@ macro_rules! transmute {
/// Safely transmutes a mutable or immutable reference of one type to an
/// immutable reference of another type of the same size.
///
/// The expression `$e` must have a concrete type, `&T` or `&mut T`, where `T:
/// Sized + IntoBytes`. The `transmute_ref!` expression must also have a
/// concrete type, `&U` (`U` is inferred from the calling context), where `U:
/// Sized + FromBytes`. It must be the case that `align_of::<T>() >=
/// align_of::<U>()`.
/// This macro behaves like an invocation of this function:
///
/// ```ignore
/// const fn transmute_ref<'src, 'dst, Src, Dst>(src: &'src Src) -> &'dst Dst
/// where
/// 'src: 'dst,
/// Src: IntoBytes + NoCell,
/// Dst: FromBytes + NoCell,
/// size_of::<Src>() == size_of::<Dst>(),
/// align_of::<Src>() >= align_of::<Dst>(),
/// {
/// # /*
/// ...
/// # */
/// }
/// ```
///
/// The lifetime of the input type, `&T` or `&mut T`, must be the same as or
/// outlive the lifetime of the output type, `&U`.
/// However, unlike a function, this macro can only be invoked when the types of
/// `Src` and `Dst` are completely concrete.
///
/// # Examples
///
Expand Down

0 comments on commit c2a4159

Please sign in to comment.