pub struct ByRef<B: SplitByteSlice> { /* private fields */ }
Expand description
A ParseStrategy
that produces [Ref<B, T>
].
This strategy is zero-copy, but one consequence is that the parser input and output cannot be retained outside the lexical scope from which the parser input was borrowed. For example, the following will not compile:
ⓘ
fn do_by_ref<'a, T: zerocopy::FromBytes + zerocopy::Unaligned>() -> (
zerocopy::Ref<&'a [u8], T>, ByRef<&'a [u8]>,
) {
let bytes: Vec<u8> = // ...
let parser = ByRef::new(bytes.as_slice());
parser.parse::<T>().unwrap()
}
The above code induces the following error:
ⓘ
error[E0515]: cannot return value referencing local variable `bytes`
Implementations§
Trait Implementations§
Source§impl<B: Debug + SplitByteSlice + PartialEq, T: Clone + Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned> Parse<ByRef<B>> for Ref<B, T>
impl<B: Debug + SplitByteSlice + PartialEq, T: Clone + Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned> Parse<ByRef<B>> for Ref<B, T>
Source§impl<B: Debug + SplitByteSlice + PartialEq> ParseStrategy for ByRef<B>
impl<B: Debug + SplitByteSlice + PartialEq> ParseStrategy for ByRef<B>
Source§fn parse<T: Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned>(
self,
) -> Option<(Self::Output<T>, Self)>
fn parse<T: Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned>( self, ) -> Option<(Self::Output<T>, Self)>
Returns a [Ref<B, T>
] as the parsed output of the next bytes in the underlying
[ByteSlice
].
Source§fn parse_slice<T: Clone + Debug + FromBytes + Immutable + PartialEq + Unaligned>(
self,
num: usize,
) -> Option<(Self::Slice<T>, Self)>
fn parse_slice<T: Clone + Debug + FromBytes + Immutable + PartialEq + Unaligned>( self, num: usize, ) -> Option<(Self::Slice<T>, Self)>
Returns a Ref<B, [T]>
as the parsed output of the next bytes in the underlying
[ByteSlice
].
Source§type Input = B
type Input = B
Type of input supported by this
ParseStrategy
.Source§type Output<T: Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned> = Ref<B, T>
type Output<T: Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned> = Ref<B, T>
Type of successfully parsed output from
Self::parse()
.Source§type Slice<T: Debug + FromBytes + Immutable + PartialEq + Unaligned> = Ref<B, [T]>
type Slice<T: Debug + FromBytes + Immutable + PartialEq + Unaligned> = Ref<B, [T]>
Type of successfully parsed output from
Self::parse_slice()
.Source§fn deref<'a, T: Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned>(
output: &'a Self::Output<T>,
) -> &'a T
fn deref<'a, T: Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned>( output: &'a Self::Output<T>, ) -> &'a T
Dereferences borrow of
Self::Output<T>
as borrow of T
.Source§fn deref_slice<'a, T: Debug + FromBytes + Immutable + PartialEq + Unaligned>(
slice: &'a Self::Slice<T>,
) -> &'a [T]
fn deref_slice<'a, T: Debug + FromBytes + Immutable + PartialEq + Unaligned>( slice: &'a Self::Slice<T>, ) -> &'a [T]
Dereferences borrow of
Self::Slice<T>
as borrow of [T]
.Source§fn len(&self) -> usize
fn len(&self) -> usize
Returns the number of bytes remaining to be parsed by this
ParseStrategy
.Source§fn into_inner(self) -> Self::Input
fn into_inner(self) -> Self::Input
Returns the complete parse input being consumed by this strategy.
impl<B: SplitByteSlice> StructuralPartialEq for ByRef<B>
Auto Trait Implementations§
impl<B> Freeze for ByRef<B>where
B: Freeze,
impl<B> RefUnwindSafe for ByRef<B>where
B: RefUnwindSafe,
impl<B> Send for ByRef<B>where
B: Send,
impl<B> Sync for ByRef<B>where
B: Sync,
impl<B> Unpin for ByRef<B>where
B: Unpin,
impl<B> UnwindSafe for ByRef<B>where
B: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)