Skip to main content

Pod

Trait Pod 

Source
pub unsafe trait Pod { }
Expand description

We use this Pod trait to implement / constraint the *read_struct functions. For the functions to work as expected and be safe, here is the rule that a type T needs to follow to be Pod:

  • T should not contain a field / type that have invalid bit patterns (no char, no bool, no pointers). We will read bytes from a file and basically transmute those bytes to T so all possible bit patterns should be ‘fine’.

§Safety

Implementing this trait for a type T requires that T is safe to initialize from any arbitrary bit pattern. This means:

  • T must not contain types with invalid bit patterns (e.g., bool, char, references, pointers)
  • All possible byte patterns must represent valid values of T
  • This is required because bytes are read from a file and transmuted to T

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Pod for u16

Source§

impl Pod for u32

Source§

impl Pod for u64

Implementors§