Choice

Struct Choice 

Source
pub struct Choice<Fst, Snd>(pub Fst, pub Snd);
Expand description

Combinator that tries the Fst combinator and if it fails, tries the Snd combinator.

Tuple Fields§

§0: Fst§1: Snd

Implementations§

Source§

impl<Fst, Snd> Choice<Fst, Snd>
where Fst: View, Snd: View, Fst::V: SpecCombinator, Snd::V: SpecCombinator + DisjointFrom<Fst::V>,

Source

pub exec fn new(fst: Fst, snd: Snd) -> o : Self

requires
snd@.disjoint_from(&fst@),
ensures
o == Choice(fst, snd),

Trait Implementations§

Source§

impl<'x, I, O, Fst, Snd> Combinator<'x, I, O> for Choice<Fst, Snd>
where I: VestInput, O: VestOutput<I>, Fst: Combinator<'x, I, O>, Snd: Combinator<'x, I, O>, Fst::V: SecureSpecCombinator<Type = <Fst::Type as View>::V>, Snd::V: SecureSpecCombinator<Type = <Snd::Type as View>::V> + DisjointFrom<Fst::V>,

Source§

exec fn length(&self, v: Self::SType) -> usize

Source§

open spec fn ex_requires(&self) -> bool

{ self.0.ex_requires() && self.1.ex_requires() }
Source§

exec fn parse(&self, s: I) -> res : Result<(usize, Self::Type), ParseError>

Source§

exec fn serialize( &self, v: Self::SType, data: &mut O, pos: usize, ) -> res : Result<usize, SerializeError>

Source§

type Type = Either<<Fst as Combinator<'x, I, O>>::Type, <Snd as Combinator<'x, I, O>>::Type>

The result type of parsing
Source§

type SType = Either<<Fst as Combinator<'x, I, O>>::SType, <Snd as Combinator<'x, I, O>>::SType>

The input type of serialization, often a reference to Self::Type. For “structural” formats though (e.g., crate::regular::sequence::Pair and crate::regular::variant::Choice), this is the tuple/sum of the corresponding Combinator::SType types.
Source§

impl<S1, S2, S3> DisjointFrom<S3> for Choice<S1, S2>

Source§

open spec fn disjoint_from(&self, other: &S3) -> bool

{ self.0.disjoint_from(other) && self.1.disjoint_from(other) }
Source§

proof fn parse_disjoint_on(&self, other: &S3, buf: Seq<u8>)

Source§

impl<Fst, Snd> SecureSpecCombinator for Choice<Fst, Snd>

Source§

open spec fn is_prefix_secure() -> bool

{ Fst::is_prefix_secure() && Snd::is_prefix_secure() }
Source§

open spec fn is_productive(&self) -> bool

{ self.0.is_productive() && self.1.is_productive() }
Source§

proof fn lemma_prefix_secure(&self, s1: Seq<u8>, s2: Seq<u8>)

Source§

proof fn theorem_serialize_parse_roundtrip(&self, v: Self::Type)

Source§

proof fn theorem_parse_serialize_roundtrip(&self, buf: Seq<u8>)

Source§

proof fn lemma_parse_length(&self, s: Seq<u8>)

Source§

proof fn lemma_parse_productive(&self, s: Seq<u8>)

Source§

fn corollary_parse_surjective(&self, v: Self::Type)

Source§

fn corollary_serialize_injective(&self, v1: Self::Type, v2: Self::Type)

Source§

fn corollary_serialize_injective_contraposition( &self, v1: Self::Type, v2: Self::Type, )

Source§

fn corollary_parse_non_malleable(&self, buf1: Seq<u8>, buf2: Seq<u8>)

Source§

fn lemma_serialize_productive(&self, v: Self::Type)

Source§

impl<Fst, Snd> SpecCombinator for Choice<Fst, Snd>
where Fst: SpecCombinator, Snd: SpecCombinator + DisjointFrom<Fst>,

Source§

open spec fn requires(&self) -> bool

{ self.0.requires() && self.1.requires() && self.1.disjoint_from(&self.0) }
Source§

open spec fn wf(&self, v: Self::Type) -> bool

{
    match v {
        Either::Left(v) => self.0.wf(v),
        Either::Right(v) => self.1.wf(v),
    }
}
Source§

open spec fn spec_parse(&self, s: Seq<u8>) -> Option<(int, Self::Type)>

{
    if let Some((n, v)) = self.0.spec_parse(s) {
        Some((n, Either::Left(v)))
    } else {
        if let Some((n, v)) = self.1.spec_parse(s) {
            Some((n, Either::Right(v)))
        } else {
            None
        }
    }
}
Source§

open spec fn spec_serialize(&self, v: Self::Type) -> Seq<u8>

{
    match v {
        Either::Left(v) => self.0.spec_serialize(v),
        Either::Right(v) => self.1.spec_serialize(v),
    }
}
Source§

type Type = Either<<Fst as SpecCombinator>::Type, <Snd as SpecCombinator>::Type>

The view of [Combinator::Result].
Source§

impl<Fst: View, Snd: View> View for Choice<Fst, Snd>

Source§

open spec fn view(&self) -> Self::V

{ Choice(self.0@, self.1@) }
Source§

type V = Choice<<Fst as View>::V, <Snd as View>::V>

Auto Trait Implementations§

§

impl<Fst, Snd> Freeze for Choice<Fst, Snd>
where Fst: Freeze, Snd: Freeze,

§

impl<Fst, Snd> RefUnwindSafe for Choice<Fst, Snd>
where Fst: RefUnwindSafe, Snd: RefUnwindSafe,

§

impl<Fst, Snd> Send for Choice<Fst, Snd>
where Fst: Send, Snd: Send,

§

impl<Fst, Snd> Sync for Choice<Fst, Snd>
where Fst: Sync, Snd: Sync,

§

impl<Fst, Snd> Unpin for Choice<Fst, Snd>
where Fst: Unpin, Snd: Unpin,

§

impl<Fst, Snd> UnwindSafe for Choice<Fst, Snd>
where Fst: UnwindSafe, Snd: 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> From<T> for T
where T: View, <T as View>::V: SpecFrom<<T as View>::V>,

Source§

exec fn ex_from(t: T) -> res : T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, VERUS_SPEC__A> FromSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: From<T>,

§

fn obeys_from_spec() -> bool

§

fn from_spec(v: T) -> VERUS_SPEC__A

Source§

impl<T, U> Into<U> for T
where T: View, U: View + From<T>, <U as View>::V: SpecFrom<<T as View>::V>,

Source§

exec fn ex_into(self) -> U

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.

§

impl<T, VERUS_SPEC__A> IntoSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: Into<T>,

§

fn obeys_into_spec() -> bool

§

fn into_spec(self) -> T

§

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

§

fn obeys_into_spec() -> bool

§

fn into_spec(self) -> U

Source§

impl<T> SpecFrom<T> for T

Source§

open spec fn spec_from(t: T) -> T

{ t }
Source§

impl<T, U> SpecInto<U> for T
where U: SpecFrom<T>,

Source§

open spec fn spec_into(self) -> U

{ U::spec_from(self) }
Source§

impl<T, U> SpecTryInto<U> for T
where U: SpecTryFrom<T>,

Source§

open spec fn spec_try_into(self) -> Result<U, <U as SpecTryFrom<T>>::Error>

{ U::spec_try_from(self) }
Source§

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

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

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

Source§

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

impl<T, VERUS_SPEC__A> TryFromSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: TryFrom<T>,

§

fn obeys_try_from_spec() -> bool

§

fn try_from_spec( v: T, ) -> Result<VERUS_SPEC__A, <VERUS_SPEC__A as TryFrom<T>>::Error>

Source§

impl<T, U> TryInto<U> for T
where T: View, U: View + TryFrom<T>, <U as View>::V: SpecTryFrom<<T as View>::V>,

Source§

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

Source§

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

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

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

Source§

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<T, VERUS_SPEC__A> TryIntoSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: TryInto<T>,

§

fn obeys_try_into_spec() -> bool

§

fn try_into_spec(self) -> Result<T, <VERUS_SPEC__A as TryInto<T>>::Error>

§

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

§

fn obeys_try_into_spec() -> bool

§

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