Trait safe_transmute::trivial::TriviallyTransmutable[][src]

pub unsafe trait TriviallyTransmutable: Copy { }

Type that can be constructed from any combination of bytes.

A type T implementing this trait means that any arbitrary slice of bytes of length size_of::<T>() can be safely interpreted as a value of that type with support for unaligned memory access. In most (but not all) cases this is a POD class or a trivially copyable class.

This serves as a marker trait for all functions in this module.

Enable the const_generics feature to implement this for arbitrary [T: TriviallyTransmutable, N] arrays, instead of just 1-32. This, of course, requires a sufficiently fresh rustc (at least 1.51).

Warning: if you transmute into a floating-point type you will have a chance to create a signaling NaN, which, while not illegal, can be unwieldy. Check out util::designalise_f{32,64}() for a remedy.

Nota bene: bool is not TriviallyTransmutable because they’re restricted to being 0 or 1, which means that an additional value check is required.

Safety

It is only safe to implement TriviallyTransmutable for a type T if it is safe to read or write a value T at the pointer of an arbitrary slice &[u8], of length size_of<T>(), as long as the same slice is well aligned in memory for reading and writing a T.

Consult the Transmutes section of the Nomicon for more details.

Implementations on Foreign Types

impl TriviallyTransmutable for u8[src]

impl TriviallyTransmutable for i8[src]

impl TriviallyTransmutable for u16[src]

impl TriviallyTransmutable for i16[src]

impl TriviallyTransmutable for u32[src]

impl TriviallyTransmutable for i32[src]

impl TriviallyTransmutable for u64[src]

impl TriviallyTransmutable for i64[src]

impl TriviallyTransmutable for usize[src]

impl TriviallyTransmutable for isize[src]

impl TriviallyTransmutable for f32[src]

impl TriviallyTransmutable for f64[src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 1][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 2][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 3][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 4][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 5][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 6][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 7][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 8][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 9][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 10][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 11][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 12][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 13][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 14][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 15][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 16][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 17][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 18][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 19][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 20][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 21][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 22][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 23][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 24][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 25][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 26][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 27][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 28][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 29][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 30][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 31][src]

impl<T: TriviallyTransmutable> TriviallyTransmutable for [T; 32][src]

Loading content...

Implementors

Loading content...