Trait rustc_metadata::rmeta::table::FixedSizeEncoding [−][src]
pub(super) trait FixedSizeEncoding: Default {
const BYTE_LEN: usize;
fn from_bytes(b: &[u8]) -> Self;
fn write_to_bytes(self, b: &mut [u8]);
fn maybe_read_from_bytes_at(b: &[u8], i: usize) -> Option<Self>;
fn write_to_bytes_at(self, b: &mut [u8], i: usize);
}
Expand description
Helper trait, for encoding to, and decoding from, a fixed number of bytes.
Used mainly for Lazy positions and lengths.
Unchecked invariant: Self::default()
should encode as [0; BYTE_LEN]
,
but this has no impact on safety.
Associated Constants
Required methods
fn from_bytes(b: &[u8]) -> Self
fn write_to_bytes(self, b: &mut [u8])
Read a Self
value (encoded as Self::BYTE_LEN
bytes),
from &b[i * Self::BYTE_LEN..]
, returning None
if i
is not in bounds, or Some(Self::from_bytes(...))
otherwise.