Trait Combinator

Source
pub trait Combinator: View
where Self::V: SecureSpecCombinator<SpecResult = <Self::Owned as View>::V>,
{ type Result<'a>: View<V = <Self::Owned as View>::V>; type Owned: View; // Required methods fn length(&self) -> Option<usize>; fn parse<'a>( &self, s: &'a [u8], ) -> Result<(usize, Self::Result<'a>), ParseError>; fn serialize( &self, v: Self::Result<'_>, data: &mut Vec<u8>, pos: usize, ) -> Result<usize, SerializeError>; }
Expand description

Implementation for parser and serializer combinators. A combinator’s view must be a SecureSpecCombinator.

Required Associated Types§

Source

type Result<'a>: View<V = <Self::Owned as View>::V>

The result type of parsing and the input type of serialization.

Source

type Owned: View

The owned parsed type. This is currently a hack to avoid lifetime bindings in SpecCombinator::SpecResult , but it can be useful if we want to have functions that return owned values (e.g. Vec<T>).

Required Methods§

Source

fn length(&self) -> Option<usize>

The length of the output buffer, if known. This can be used to optimize serialization by pre-allocating the buffer.

Source

fn parse<'a>( &self, s: &'a [u8], ) -> Result<(usize, Self::Result<'a>), ParseError>

The parsing function.

Source

fn serialize( &self, v: Self::Result<'_>, data: &mut Vec<u8>, pos: usize, ) -> Result<usize, SerializeError>

The serialization function.

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.

Implementations on Foreign Types§

Source§

impl<C: Combinator> Combinator for &C
where C::V: SecureSpecCombinator<SpecResult = <C::Owned as View>::V>,

Source§

type Result<'a> = <C as Combinator>::Result<'a>

Source§

type Owned = <C as Combinator>::Owned

Source§

fn length(&self) -> Option<usize>

Source§

fn parse<'a>( &self, s: &'a [u8], ) -> Result<(usize, Self::Result<'a>), ParseError>

Source§

fn serialize( &self, v: Self::Result<'_>, data: &mut Vec<u8>, pos: usize, ) -> Result<usize, SerializeError>

Source§

impl<Fst, Snd> Combinator for (Fst, Snd)
where Fst: Combinator, Snd: Combinator, Fst::V: SecureSpecCombinator<SpecResult = <Fst::Owned as View>::V>, Snd::V: SecureSpecCombinator<SpecResult = <Snd::Owned as View>::V>,

Source§

type Result<'a> = (<Fst as Combinator>::Result<'a>, <Snd as Combinator>::Result<'a>)

Source§

type Owned = (<Fst as Combinator>::Owned, <Snd as Combinator>::Owned)

Source§

fn length(&self) -> Option<usize>

Source§

fn parse<'a>( &self, s: &'a [u8], ) -> Result<(usize, Self::Result<'a>), ParseError>

Source§

fn serialize( &self, v: Self::Result<'_>, data: &mut Vec<u8>, pos: usize, ) -> Result<usize, SerializeError>

Implementors§

Source§

impl Combinator for Bytes

Source§

type Result<'a> = &'a [u8]

Source§

type Owned = Vec<u8>

Source§

impl Combinator for Fail

Source§

impl Combinator for Tail

Source§

type Result<'a> = &'a [u8]

Source§

type Owned = Vec<u8>

Source§

impl Combinator for U8

Source§

impl Combinator for U16

Source§

impl Combinator for U32

Source§

impl Combinator for U64

Source§

impl<'a, Inner> Combinator for Tag<Inner, &'a [u8]>
where Inner: for<'b> Combinator<Result<'b> = &'b [u8], Owned = Vec<u8>>, Inner::V: SecureSpecCombinator<SpecResult = Seq<u8>>,

Source§

impl<C: Combinator> Combinator for Repeat<C>
where <C as View>::V: SecureSpecCombinator<SpecResult = <C::Owned as View>::V>,

Source§

impl<Fst, Snd> Combinator for OrdChoice<Fst, Snd>
where Fst: Combinator, Snd: Combinator, Fst::V: SecureSpecCombinator<SpecResult = <Fst::Owned as View>::V>, Snd::V: SecureSpecCombinator<SpecResult = <Snd::Owned as View>::V> + DisjointFrom<Fst::V>,

Source§

type Result<'a> = Either<<Fst as Combinator>::Result<'a>, <Snd as Combinator>::Result<'a>>

Source§

type Owned = Either<<Fst as Combinator>::Owned, <Snd as Combinator>::Owned>

Source§

impl<Fst, Snd> Combinator for Preceded<Fst, Snd>
where Fst: for<'a> Combinator<Result<'a> = (), Owned = ()>, Snd: Combinator, Fst::V: SecureSpecCombinator<SpecResult = ()>, Snd::V: SecureSpecCombinator<SpecResult = <Snd::Owned as View>::V>,

Source§

type Result<'a> = <Snd as Combinator>::Result<'a>

Source§

type Owned = <Snd as Combinator>::Owned

Source§

impl<Fst, Snd, F> Combinator for Depend<Fst, Snd, F>
where Fst: Combinator, Snd: Combinator, Fst::V: SecureSpecCombinator<SpecResult = <Fst::Owned as View>::V>, Snd::V: SecureSpecCombinator<SpecResult = <Snd::Owned as View>::V>, F: for<'a> Fn(Fst::Result<'a>) -> Snd, for<'a> Fst::Result<'a>: Copy,

Source§

type Result<'a> = (<Fst as Combinator>::Result<'a>, <Snd as Combinator>::Result<'a>)

Source§

type Owned = (<Fst as Combinator>::Owned, <Snd as Combinator>::Owned)

Source§

impl<Inner, M> Combinator for Mapped<Inner, M>
where Inner: Combinator, Inner::V: SecureSpecCombinator<SpecResult = <Inner::Owned as View>::V>, for<'a> M: Iso<Src<'a> = Inner::Result<'a>, SrcOwned = Inner::Owned>, for<'a> Inner::Result<'a>: From<M::Dst<'a>> + View, for<'a> M::Dst<'a>: From<Inner::Result<'a>> + View, M::V: SpecIso<Src = <Inner::Owned as View>::V, Dst = <M::DstOwned as View>::V>, <Inner::Owned as View>::V: SpecFrom<<M::DstOwned as View>::V>, <M::DstOwned as View>::V: SpecFrom<<Inner::Owned as View>::V>,

Source§

type Result<'a> = <M as Iso>::Dst<'a>

Source§

type Owned = <M as Iso>::DstOwned

Source§

impl<Inner, M> Combinator for TryMap<Inner, M>
where Inner: Combinator, Inner::V: SecureSpecCombinator<SpecResult = <Inner::Owned as View>::V>, for<'a> M: TryFromInto<Src<'a> = Inner::Result<'a>, SrcOwned = Inner::Owned>, for<'a> Inner::Result<'a>: TryFrom<M::Dst<'a>> + View, for<'a> M::Dst<'a>: TryFrom<Inner::Result<'a>> + View, M::V: SpecTryFromInto<Src = <Inner::Owned as View>::V, Dst = <M::DstOwned as View>::V>, <Inner::Owned as View>::V: SpecTryFrom<<M::DstOwned as View>::V>, <M::DstOwned as View>::V: SpecTryFrom<<Inner::Owned as View>::V>,

Source§

type Result<'a> = <M as TryFromInto>::Dst<'a>

Source§

type Owned = <M as TryFromInto>::DstOwned

Source§

impl<Inner, P> Combinator for Refined<Inner, P>
where Inner: Combinator, Inner::V: SecureSpecCombinator<SpecResult = <Inner::Owned as View>::V>, P: for<'a> Pred<Input<'a> = Inner::Result<'a>, InputOwned = Inner::Owned>, P::V: SpecPred<Input = <Inner::Owned as View>::V>,

Source§

type Result<'a> = <Inner as Combinator>::Result<'a>

Source§

type Owned = <Inner as Combinator>::Owned

Source§

impl<Inner, T> Combinator for Tag<Inner, T>
where Inner: for<'a> Combinator<Result<'a> = T, Owned = T>, Inner::V: SecureSpecCombinator<SpecResult = T::V>, T: FromToBytes,

Source§

impl<Inner, const N: usize> Combinator for Tag<Inner, [u8; N]>
where Inner: for<'b> Combinator<Result<'b> = &'b [u8], Owned = Vec<u8>>, Inner::V: SecureSpecCombinator<SpecResult = Seq<u8>>,

Source§

impl<Inner: Combinator> Combinator for Cond<Inner>
where Inner::V: SecureSpecCombinator<SpecResult = <Inner::Owned as View>::V>,

Source§

type Result<'a> = <Inner as Combinator>::Result<'a>

Source§

type Owned = <Inner as Combinator>::Owned

Source§

impl<Next: Combinator> Combinator for AndThen<Bytes, Next>
where Next::V: SecureSpecCombinator<SpecResult = <Next::Owned as View>::V>,

Source§

type Result<'a> = <Next as Combinator>::Result<'a>

Source§

type Owned = <Next as Combinator>::Owned

Source§

impl<T> Combinator for BuilderCombinator<T>
where T: Builder + View, T::V: Builder,

Source§

impl<const N: usize> Combinator for BytesN<N>

Source§

type Result<'a> = &'a [u8]

Source§

type Owned = Vec<u8>