[−][src]Trait zerocopy::FromBytes
Types for which any byte pattern is valid.
WARNING: Do not implement this trait yourself! Instead, use
#[derive(FromBytes)].
FromBytes types can safely be deserialized from an untrusted sequence of
bytes because any byte sequence corresponds to a valid instance of the type.
Safety
If T: FromBytes, then unsafe code may assume that it is sound to treat any
initialized sequence of bytes of length size_of::<T>() as a T. If a type
is marked as FromBytes which violates this contract, it may cause
undefined behavior.
If a type has the following properties, then it is safe to implement
FromBytes for that type:
- If the type is a struct:
- It must have a defined representation (
repr(C),repr(transparent), orrepr(packed)) - All of its fields must implement
FromBytes
- It must have a defined representation (
- If the type is an enum:
- It must be a C-like enum (meaning that all variants have no fields)
- It must have a defined representation (
reprsC,u8,u16,u32,u64,usize,i8,i16,i32,i64, orisize). - The maximum number of discriminants must be used (so that every possible
bit pattern is a valid one). Be very careful when using the
C,usize, orisizerepresentations, as their size is platform-dependent.
Implementations on Foreign Types
impl<T> FromBytes for PhantomData<T>[src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
Implementors
impl FromBytes for ()[src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl FromBytes for i8[src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl FromBytes for i16[src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl FromBytes for i32[src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl FromBytes for i64[src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl FromBytes for i128[src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl FromBytes for isize[src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl FromBytes for u8[src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl FromBytes for u16[src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl FromBytes for u32[src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl FromBytes for u64[src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl FromBytes for u128[src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl FromBytes for usize[src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 0][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 1][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 2][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 3][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 4][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 5][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 6][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 7][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 8][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 9][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 10][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 11][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 12][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 13][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 14][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 15][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 16][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 17][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 18][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 19][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 20][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 21][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 22][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 23][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 24][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 25][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 26][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 27][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 28][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 29][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 30][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 31][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T; 32][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,
impl<T: FromBytes> FromBytes for [T][src]
fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized, [src]
Self: Sized,