Trait zero::Pod

source ·
pub unsafe trait Pod: Sized { }
Expand description

Implementing this trait means that the concrete type is plain old data (POD). Precisely, by implementing Pod the programmer asserts that it is safe to read the type from binary slices provided to read, etc.

Some guidelines for when Pod may be implemented (note that whether Pod should be implemented or not is a function of both the type and the input data. I.e., just because a type is Pod in one context does not mean it should be in another):

  • primitive numeric types (u8, i64, f32, etc.) are fine,
  • bools are fine, if the provided data ensures they may have only the values 0 or 1 (note that this is a stricter requirement that C),
  • structs may be Pod if they have a repr(C) or repr(packed) attribute to prevent rustc from performing field reordering. The former requires that the supplied data has the correct alignment.
  • enums must have valid discriminants in the supplied data, this is probably only feasible if they have a specified representation,
  • there must not be invalid enum variants in the data,
  • any kind of pointer is probably a bad idea. Theoretically one could make raw pointers work.

Implementations on Foreign Types§

Implementors§