Trait SplitAt
unsafe trait SplitAt: KnownLayout<PointerMetadata = usize>
Types that can be split in two.
This trait generalizes Rust's existing support for splitting slices to support slices and slice-based dynamically-sized types ("slice DSTs").
Implementation
Do not implement this trait yourself! Instead, use
#[derive(SplitAt)]; e.g.:
# use ;
This derive performs a sophisticated, compile-time safety analysis to
determine whether a type is SplitAt.
Safety
This trait does not convey any safety guarantees to code outside this crate.
You must not rely on the #[doc(hidden)] internals of SplitAt. Future
releases of zerocopy may make backwards-breaking changes to these items,
including changes that only affect soundness, which may cause code which
uses those items to silently become unsound.
Associated Types
type ElemThe element type of the trailing slice.
Provided Methods
unsafe fn split_at_unchecked(self: &Self, l_len: usize) -> Split<&Self>Unsafely splits
selfin two.Safety
The caller promises that
l_lenis not greater than the length ofself's trailing slice.fn split_at(self: &Self, l_len: usize) -> Option<Split<&Self>>Attempts to split
selfin two.Returns
Noneifl_lenis greater than the length ofself's trailing slice.Examples
use ; # use *; // These bytes encode a `Packet`. let bytes = &; let packet = ref_from_bytes.unwrap; assert_eq!; assert_eq!; // Attempt to split `packet` at `length`. let split = packet.split_at.unwrap; // Use the `Immutable` bound on `Packet` to prove that it's okay to // return concurrent references to `packet` and `rest`. let = split.via_immutable; assert_eq!; assert_eq!; assert_eq!;unsafe fn split_at_mut_unchecked(self: &mut Self, l_len: usize) -> Split<&mut Self>Unsafely splits
selfin two.Safety
The caller promises that
l_lenis not greater than the length ofself's trailing slice.fn split_at_mut(self: &mut Self, l_len: usize) -> Option<Split<&mut Self>>Attempts to split
selfin two.Returns
Noneifl_lenis greater than the length ofself's trailing slice, or if the givenl_lenwould result in the trailing padding of the left portion overlapping the right portion.Examples
use ; # use *; // These bytes encode a `Packet`. let mut bytes = &mut ; let packet = mut_from_bytes.unwrap; assert_eq!; assert_eq!; assert_eq!; assert_eq!;
Implementors
impl<T> SplitAt for [T]