devela::_dep::bytemuck::checked

Function try_from_bytes

pub fn try_from_bytes<T>(s: &[u8]) -> Result<&T, CheckedCastError> 
Available on crate feature dep_bytemuck only.
Expand description

Re-interprets &[u8] as &T.

§Failure

  • If the slice isn’t aligned for the new type
  • If the slice’s length isn’t exactly the size of the new type
  • If the slice contains an invalid bit pattern for T