pub trait ParseStrategy:
Debug
+ PartialEq
+ Sized {
type Input;
type Output<T: Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned>: Debug + PartialEq;
type Slice<T: Debug + FromBytes + Immutable + PartialEq + Unaligned>: Debug + PartialEq;
// Required methods
fn parse<T: Clone + Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned>(
self,
) -> Option<(Self::Output<T>, Self)>;
fn parse_slice<T: Clone + Debug + FromBytes + Immutable + PartialEq + Unaligned>(
self,
count: usize,
) -> Option<(Self::Slice<T>, Self)>;
fn deref<'a, T: Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned>(
output: &'a Self::Output<T>,
) -> &'a T;
fn deref_slice<'a, T: Debug + FromBytes + Immutable + PartialEq + Unaligned>(
slice: &'a Self::Slice<T>,
) -> &'a [T];
fn len(&self) -> usize;
fn into_inner(self) -> Self::Input;
}
Expand description
A strategy for parsing data. Parsed structures that may contain references to parsed data are generally of the form:
type ParserOutput<PS: ParseStrategy> {
ref_or_value_t: PS::Output<T>,
// ...
}
The above pattern allows ParseStrategy
implementations to dictate how values are stored (by
copied value, or reference to parser input data).
Required Associated Types§
Sourcetype Input
type Input
Type of input supported by this ParseStrategy
.
Required Methods§
Sourcefn parse<T: Clone + Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned>(
self,
) -> Option<(Self::Output<T>, Self)>
fn parse<T: Clone + Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned>( self, ) -> Option<(Self::Output<T>, Self)>
Parses a Self::Output<T>
from the next bytes underlying self
. If the parse succeeds,
then return (Some(output), self)
after advancing past the parsed bytes. Otherwise, return
None
without advancing past the parsed bytes.
Sourcefn parse_slice<T: Clone + Debug + FromBytes + Immutable + PartialEq + Unaligned>(
self,
count: usize,
) -> Option<(Self::Slice<T>, Self)>
fn parse_slice<T: Clone + Debug + FromBytes + Immutable + PartialEq + Unaligned>( self, count: usize, ) -> Option<(Self::Slice<T>, Self)>
Parses a Self::Slice<T>
of count
elements from the next bytes underlying self
. If the
parse succeeds, then return (Some(slice), self)
after advancing past the parsed bytes.
Otherwise, return None
without advancing past the parsed bytes.
Sourcefn 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
.
Sourcefn 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]
.
Sourcefn len(&self) -> usize
fn len(&self) -> usize
Returns the number of bytes remaining to be parsed by this ParseStrategy
.
Sourcefn into_inner(self) -> Self::Input
fn into_inner(self) -> Self::Input
Returns the complete parse input being consumed by this strategy.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.