Struct selinux::policy::parser::ByRef

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

source§

impl<B: SplitByteSlice + Clone> ByRef<B>

source

pub fn new(byte_slice: B) -> Self

Returns a new ByRef that wraps bytes_slice.

Trait Implementations§

source§

impl<B: Clone + SplitByteSlice> Clone for ByRef<B>

source§

fn clone(&self) -> ByRef<B>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<B: Debug + SplitByteSlice + PartialEq, T: Clone + Debug + FromBytes + KnownLayout + Immutable + PartialEq + Unaligned> Parse<ByRef<B>> for Ref<B, T>

§

type Error = Error

The type of error that may be returned from parse(), usually ParseError or anyhow::Error.
source§

fn parse(bytes: ByRef<B>) -> Result<(Self, ByRef<B>), Self::Error>

Parses a Self from bytes, returning the Self and trailing bytes, or an error if bytes corresponding to a Self are malformed.
source§

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)>

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)>

Returns a Ref<B, [T]> as the parsed output of the next bytes in the underlying [ByteSlice].

§

type Input = B

Type of input supported by this ParseStrategy.
§

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

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

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

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

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

source§

fn eq(&self, other: &ByRef<B>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<B, A> LockBefore<B> for A
where B: LockAfter<A>,

§

impl<B, A> LockEqualOrBefore<B> for A
where A: LockBefore<B>,