Function plain::from_bytes [] [src]

pub fn from_bytes<T: ?Sized>(bytes: &[u8]) -> Result<&T, Error> where T: Methods

Safely converts a byte slice to a Plain type reference.

However, if the byte slice is not long enough to contain target type, or if it doesn't satisfy the type's alignment requirements, the function returns an error.

If the target type is a slice, its length will be set appropriately to the length of the input slice. E.g. a byte array of length 16 would result in a slice &[u32] with 4 entries.

It is currently unspecified what happens when the result is a slice and the input slice length is not a multiple of the result type.

In most cases it's much preferrable to allocate a value/slice of the target type and use as_mut_bytes() instead.