Trait cote::prelude::Policy

source ·
pub trait Policy {
    type Ret;
    type Set;
    type Inv<'a>;
    type Ser;
    type Error: Into<Error>;

    // Required method
    fn parse(
        &mut self,
        set: &mut Self::Set,
        inv: &mut Self::Inv<'_>,
        ser: &mut Self::Ser,
        args: Rc<Args>
    ) -> Result<Self::Ret, Self::Error>;
}
Expand description

Policy doing real parsing work.

§Example


#[derive(Debug)]
pub struct EmptyPolicy<Set, Ser>(PhantomData<(Set, Ser)>);

// An empty policy do nothing.
impl<S: Set, Ser> Policy for EmptyPolicy<S, Ser> {
    type Ret = bool;

    type Set = S;

    type Inv<'a> = Invoker<'a, S, Ser>;

    type Ser = Ser;

    type Error = Error;

    fn parse<'a>(
        &mut self,
        _: &mut Self::Set,
        _: &mut Self::Inv<'a>,
        _: &mut Self::Ser,
        _: ARef<Args>,
   ) -> Result<bool, Error> {
        // ... parsing logical code
       Ok(true)
    }
}

Required Associated Types§

Required Methods§

source

fn parse( &mut self, set: &mut Self::Set, inv: &mut Self::Inv<'_>, ser: &mut Self::Ser, args: Rc<Args> ) -> Result<Self::Ret, Self::Error>

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<'inv, Set, Ser> Policy for NullPolicy<'inv, Set, Ser>

§

type Ret = ReturnVal

§

type Set = Parser<'inv, Set, Ser>

§

type Inv<'a> = Invoker<'a, Parser<'inv, Set, Ser>, Ser>

§

type Ser = Ser

§

type Error = Error

source§

impl<Set, Ser, Chk> Policy for DelayPolicy<Set, Ser, Chk>
where <<Set as Set>::Ctor as Ctor>::Opt: Opt, Chk: SetChecker<Set>, Set: Set + OptParser + OptValidator,

§

type Ret = ReturnVal

§

type Set = Set

§

type Inv<'a> = Invoker<'a, Set, Ser>

§

type Ser = Ser

§

type Error = Error

source§

impl<Set, Ser, Chk> Policy for FwdPolicy<Set, Ser, Chk>
where <<Set as Set>::Ctor as Ctor>::Opt: Opt, Chk: SetChecker<Set>, Set: Set + OptParser + OptValidator,

§

type Ret = ReturnVal

§

type Set = Set

§

type Inv<'a> = Invoker<'a, Set, Ser>

§

type Ser = Ser

§

type Error = Error

source§

impl<Set, Ser, Chk> Policy for PrePolicy<Set, Ser, Chk>
where <<Set as Set>::Ctor as Ctor>::Opt: Opt, Chk: SetChecker<Set>, Set: Set + OptParser + OptValidator,

§

type Ret = ReturnVal

§

type Set = Set

§

type Inv<'a> = Invoker<'a, Set, Ser>

§

type Ser = Ser

§

type Error = Error