Skip to main content

ref_from_prefix_suffix

Function ref_from_prefix_suffix 

Source
pub(crate) fn ref_from_prefix_suffix<S, T>(
    source: &S,
    meta: Option<T::PointerMetadata>,
    cast_type: CastType,
) -> Result<(&T, &[u8]), CastError<&S, T>>
Expand description

Interprets the given affix of source’s bytes as a &T.

This method uses meta if provided; otherwise, it computes the largest possible size of T that can fit in the prefix or suffix bytes of source. It returns both a reference to those bytes interpreted as a T, and a reference to the excess bytes. If there are insufficient bytes, or if that affix of source is not appropriately aligned, this returns Err containing the original &S.