Module zaplib::byte_extract
source · [−]Expand description
Read the desired data type in as few instructions as possible. This is technically
unsafe if you’re reading past the end of a buffer, but we’re not going to worry
about that for performance. This saves a relatively expensive boundary
check when using safe functions like from_le_bytes
with try_into().unwrap()
.
TODO(JP): see if we can implement this with generics; might be tricky since you can only specialize on traits. Or might be able to use code generation here?