Trait selinux::policy::parser::ParseStrategy

source ·
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§

source

type Input

Type of input supported by this ParseStrategy.

source

type Output<T: Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned>: Debug + PartialEq

Type of successfully parsed output from Self::parse().

source

type Slice<T: Debug + FromBytes + Immutable + PartialEq + Unaligned>: Debug + PartialEq

Type of successfully parsed output from Self::parse_slice().

Required Methods§

source

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.

source

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.

source

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]

Dereferences borrow of Self::Slice<T> as borrow of [T].

source

fn len(&self) -> usize

Returns the number of bytes remaining to be parsed by this ParseStrategy.

source

fn into_inner(self) -> Self::Input

Returns the complete parse input being consumed by this strategy.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<B: Debug + SplitByteSlice + PartialEq> ParseStrategy for ByRef<B>

§

type Input = B

§

type Output<T: Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned> = Ref<B, T>

§

type Slice<T: Debug + FromBytes + Immutable + PartialEq + Unaligned> = Ref<B, [T]>

source§

impl<T: AsRef<[u8]> + Debug + PartialEq> ParseStrategy for ByValue<T>
where Cursor<T>: Debug + ParseCursor + PartialEq,

§

type Input = T

§

type Output<O: Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned> = O

§

type Slice<S: Debug + FromBytes + Immutable + PartialEq + Unaligned> = Vec<S>