Skip to content

Commit 423beb7

Browse files
committed
Use pseudocode to document transmute, transmute_mut
Partially addresses #1046.
1 parent 9fe8aae commit 423beb7

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

src/lib.rs

+43-13
Original file line numberDiff line numberDiff line change
@@ -4347,14 +4347,30 @@ mod simd {
43474347
/// Safely transmutes a value of one type to a value of another type of the same
43484348
/// size.
43494349
///
4350-
/// The expression `$e` must have a concrete type, `T`, which implements
4351-
/// `IntoBytes`. The `transmute!` expression must also have a concrete type, `U`
4352-
/// (`U` is inferred from the calling context), and `U` must implement
4353-
/// `FromBytes`.
4350+
/// This macro behaves like an invocation of this function:
43544351
///
4355-
/// Note that the `T` produced by the expression `$e` will *not* be dropped.
4356-
/// Semantically, its bits will be copied into a new value of type `U`, the
4357-
/// original `T` will be forgotten, and the value of type `U` will be returned.
4352+
/// ```ignore
4353+
/// const fn transmute<Src, Dst>(src: Src) -> Dst
4354+
/// where
4355+
/// Src: IntoBytes,
4356+
/// Dst: FromBytes,
4357+
/// size_of::<Src>() == size_of::<Dst>(),
4358+
/// {
4359+
/// # /*
4360+
/// ...
4361+
/// # */
4362+
/// }
4363+
/// ```
4364+
///
4365+
/// However, unlike a function, this macro can only be invoked when the types of
4366+
/// `Src` and `Dst` are completely concrete. The types `Src` and `Dst` are
4367+
/// inferred from the calling context; they cannot be explicitly specified in
4368+
/// the macro invocation.
4369+
///
4370+
/// Note that the `Src` produced by the expression `$e` will *not* be dropped.
4371+
/// Semantically, its bits will be copied into a new value of type `Dst`, the
4372+
/// original `Src` will be forgotten, and the value of type `Dst` will be
4373+
/// returned.
43584374
///
43594375
/// # Examples
43604376
///
@@ -4562,13 +4578,27 @@ macro_rules! transmute_ref {
45624578
/// Safely transmutes a mutable reference of one type to a mutable reference of
45634579
/// another type of the same size.
45644580
///
4565-
/// The expression `$e` must have a concrete type, `&mut T`, where `T: Sized +
4566-
/// IntoBytes`. The `transmute_mut!` expression must also have a concrete type,
4567-
/// `&mut U` (`U` is inferred from the calling context), where `U: Sized +
4568-
/// FromBytes`. It must be the case that `align_of::<T>() >= align_of::<U>()`.
4581+
/// This macro behaves like an invocation of this function:
45694582
///
4570-
/// The lifetime of the input type, `&mut T`, must be the same as or outlive the
4571-
/// lifetime of the output type, `&mut U`.
4583+
/// ```ignore
4584+
/// const fn transmute_mut<'src, 'dst, Src, Dst>(src: &'src mut Src) -> &'dst mut Dst
4585+
/// where
4586+
/// 'src: 'dst,
4587+
/// Src: FromBytes + IntoBytes + NoCell,
4588+
/// Dst: FromBytes + IntoBytes + NoCell,
4589+
/// size_of::<Src>() == size_of::<Dst>(),
4590+
/// align_of::<Src>() >= align_of::<Dst>(),
4591+
/// {
4592+
/// # /*
4593+
/// ...
4594+
/// # */
4595+
/// }
4596+
/// ```
4597+
///
4598+
/// However, unlike a function, this macro can only be invoked when the types of
4599+
/// `Src` and `Dst` are completely concrete. The types `Src` and `Dst` are
4600+
/// inferred from the calling context; they cannot be explicitly specified in
4601+
/// the macro invocation.
45724602
///
45734603
/// # Examples
45744604
///

0 commit comments

Comments
 (0)