Module safe_transmute::trivial[][src]

Transmutation of trivial objects

Functions in this module are guarded from out-of-bounds memory access and from unsafe transmutation target types through the use of the TriviallyTransmutable) trait.

If a certain type can be safely constructed out of any byte combination, then it may implement this trait. This is the case for primitive integer types (e.g. i32, u32, i64), arrays of other trivially transmutable types, and repr(C) structs composed of trivially transmutable values.

However, they are still not entirely safe because the source data may not be correctly aligned for reading and writing a value of the target type. The effects of this range from less performance (e.g. x86) to trapping or address flooring (e.g. ARM), but this is undefined behavior nonetheless.

Traits

TriviallyTransmutable

Type that can be constructed from any combination of bytes.

Functions

align_to

Transmute the slice to a slice of another type, ensuring alignment of the types is maintained.

align_to_mut

Transmute the slice to a slice of another type, ensuring alignment of the types is maintained.

guarded_transmute_pod_many_pedanticDeprecated

View a byte slice as a slice of a trivially transmutable type.

guarded_transmute_pod_many_permissiveDeprecated

View a byte slice as a slice of a trivially transmutable type.

transmute_trivial

Transmute a byte slice into a single instance of a trivially transmutable type.

transmute_trivial_many

Transmute a byte slice into a single instance of a trivially transmutable type.

transmute_trivial_many_mut

Transmute a byte slice into a single instance of a trivially transmutable type.

transmute_trivial_pedantic

Transmute a byte slice into a single instance of a trivially transmutable type.

transmute_trivial_vec

Transform a vector into a vector of another element type.