Skip to main content

Opt

Struct Opt 

Source
pub struct Opt<A>(pub A);
Expand description

Optional combinator: denotes an optional field.

Parsing semantics: tries A, returning Some(a) on success; on failure, returns None without consuming input.

Serialization semantics: if the value is Some(a), serializes a with A; if the value is None, produces no output.

§Consistency

A value v is consistent with Opt<A> iff either v is consistent with A or v is None.

§Note

This combinator is mostly used internally to specify Optional<A, B>, which is able to disambiguate A and B and hence more compositional.

Tuple Fields§

§0: A

Trait Implementations§

Source§

impl<A, T> ByteLen<Option<T>> for Opt<A>
where T: DeepView, A: ByteLen<T>,

Source§

open spec fn exec_inv(&self) -> bool

{ self.0.exec_inv() }
Source§

exec fn length(&self, v: &Option<T>) -> len : usize

Source§

impl<A: Clone> Clone for Opt<A>

Source§

exec fn clone(&self) -> cloned : Self

ensures
call_ensures(A::clone, (&self.0,), cloned.0),
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<A> Consistency for Opt<A>
where A: Consistency,

Source§

open spec fn consistent(&self, v: Self::Val) -> bool

{
    match v {
        None => true,
        Some(vv) => self.0.consistent(vv),
    }
}
Source§

type Val = Option<<A as Consistency>::Val>

The type of values whose consistency is being checked.
Source§

impl<A, T> DerOrd<Option<T>> for Opt<A>
where T: DeepView, A: DerOrd<T>,

Source§

proof fn lemma_der_serialize_len(&self, value: Option<T::V>)

Source§

open spec fn der_remaining( &self, value: Option<T::V>, state: OptDerState<A::State>, ) -> Seq<u8>

{
    match (value, state) {
        (Some(value), OptDerState::Some(state)) => self.0.der_remaining(value, state),
        (None, OptDerState::None) => Seq::empty(),
        _ => Seq::empty(),
    }
}
Source§

open spec fn der_state_valid( &self, value: Option<T::V>, state: OptDerState<A::State>, ) -> bool

{
    match (value, state) {
        (Some(value), OptDerState::Some(state)) => self.0.der_state_valid(value, state),
        (None, OptDerState::None) => true,
        _ => false,
    }
}
Source§

exec fn der_start(&self, o: &Option<T>) -> state : OptDerState<A::State>

Source§

exec fn der_next( &self, o: &Option<T>, state: &mut OptDerState<A::State>, ) -> next : Option<u8>

Source§

fn der_leq(&self, left: &T, right: &T) -> bool

Source§

impl<A: DerState> DerState for Opt<A>

Source§

impl<A> EquivSerializers for Opt<A>

Source§

open spec fn equiv_inv(&self) -> bool

{ self.0.equiv_inv() }
Source§

proof fn lemma_serialize_equiv_on_empty(&self, v: Self::SVal)

Source§

impl<A> EquivSerializersGeneral for Opt<A>

Source§

open spec fn equiv_general_inv(&self) -> bool

{ self.0.equiv_general_inv() }
Source§

proof fn lemma_serialize_equiv(&self, v: Self::SVal, obuf: Seq<u8>)

Source§

impl<A: GoodSerializer> GoodSerializer for Opt<A>

Source§

open spec fn serialize_inv(&self) -> bool

{ self.0.serialize_inv() }
Source§

proof fn lemma_serialize_len(&self, v: Self::SVal)

Source§

impl<Inner: MinMaxByteLen> MinMaxByteLen for Opt<Inner>

Source§

open spec fn min(&self) -> nat

{ 0 }
Source§

open spec fn max(&self) -> nat

{ self.0.max() }
Source§

proof fn lemma_min_max_byte_len(&self, v: Self::T)

Source§

impl<A: NonMalleable> NonMalleable for Opt<A>

Source§

open spec fn nonmal_inv(&self) -> bool

{ self.0.nonmal_inv() }
Source§

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

Source§

impl<A> NonTailFmt for Opt<A>
where A: NonTailFmt,

Source§

open spec fn serialize_dps_inv(&self) -> bool

{ self.0.serialize_dps_inv() }
Source§

proof fn lemma_serialize_dps_prepend(&self, v: Self::SValue, obuf: Seq<u8>)

Source§

proof fn lemma_serialize_dps_len(&self, v: Self::SValue, obuf: Seq<u8>)

Source§

impl<I, A> Parser<I> for Opt<A>
where I: View<V = Seq<u8>>, A: Parser<I>,

Source§

open spec fn exec_inv(&self) -> bool

{ self.0.exec_inv() }
Source§

exec fn parse(&self, ibuf: &I) -> PResult<Self::PT>

Source§

type PT = Option<<A as Parser<I>>::PT>

Executable value returned by this parser.
Source§

impl<A, T> Prepare<Option<T>> for Opt<A>
where T: DeepView, A: Prepare<T>,

Source§

open spec fn exec_inv(&self) -> bool

{ self.0.exec_inv() }
Source§

exec fn prepare(&self, v: &Option<T>) -> checked : Result<usize, PreSerializeError>

Source§

impl<A: SafeParser> Productive for Opt<A>

Source§

open spec fn productive_inv(&self) -> bool

{ false }
Source§

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

Source§

impl<A> SafeParser for Opt<A>
where A: SafeParser,

Source§

open spec fn safe_inv(&self) -> bool

{ self.0.safe_inv() }
Source§

proof fn lemma_parse_safe(&self, ibuf: Seq<u8>)

Source§

impl<Output: OutputBuf, A, T> Serializer<Output, Option<T>> for Opt<A>
where T: DeepView, A: Serializer<Output, T>,

Source§

open spec fn exec_inv(&self) -> bool

{ self.0.exec_inv() }
Source§

exec fn serialize_into(&self, v: &Option<T>, obuf: &mut Output)

Source§

impl<A> SoundParser for Opt<A>
where A: SoundParser,

Source§

open spec fn sound_inv(&self) -> bool

{ self.0.sound_inv() }
Source§

proof fn lemma_parse_sound_consumption(&self, ibuf: Seq<u8>)

Source§

proof fn lemma_parse_sound_value(&self, ibuf: Seq<u8>)

Source§

impl<Inner: SpecByteLen> SpecByteLen for Opt<Inner>

Source§

open spec fn byte_len(&self, v: Self::T) -> nat

{
    match v {
        None => 0,
        Some(vv) => self.0.byte_len(vv),
    }
}
Source§

type T = Option<<Inner as SpecByteLen>::T>

The type of values whose byte length is being computed.
Source§

impl<A> SpecParser for Opt<A>
where A: SpecParser,

Source§

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

{
    match self.0.spec_parse(ibuf) {
        Some((n, v)) => Some((n, Some(v))),
        None => Some((0, None)),
    }
}
Source§

type PVal = Option<<A as SpecParser>::PVal>

The type of parsed values.
Source§

impl<A> SpecSerializer for Opt<A>
where A: SpecSerializer,

Source§

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

{
    match v {
        None => Seq::empty(),
        Some(vv) => self.0.spec_serialize(vv),
    }
}
Source§

type SVal = Option<<A as SpecSerializer>::SVal>

The type of values to be serialized.
Source§

impl<A> SpecSerializerDps for Opt<A>

Source§

open spec fn spec_serialize_dps(&self, v: Self::SValue, obuf: Seq<u8>) -> Seq<u8>

{
    match v {
        None => obuf,
        Some(vv) => self.0.spec_serialize_dps(vv, obuf),
    }
}
Source§

type SValue = Option<<A as SpecSerializerDps>::SValue>

The type of values to be serialized.
Source§

impl<Inner: ValueByteLen> ValueByteLen for Opt<Inner>

Source§

open spec fn value_byte_len(v: Self::T) -> nat

{
    match v {
        None => 0,
        Some(vv) => Inner::value_byte_len(vv),
    }
}
Source§

proof fn lemma_value_len_matches_byte_len(&self, v: Self::T)

Source§

impl<A: Copy> Copy for Opt<A>

Auto Trait Implementations§

§

impl<A> Freeze for Opt<A>
where A: Freeze,

§

impl<A> RefUnwindSafe for Opt<A>
where A: RefUnwindSafe,

§

impl<A> Send for Opt<A>
where A: Send,

§

impl<A> Sync for Opt<A>
where A: Sync,

§

impl<A> Unpin for Opt<A>
where A: Unpin,

§

impl<A> UnsafeUnpin for Opt<A>
where A: UnsafeUnpin,

§

impl<A> UnwindSafe for Opt<A>
where A: 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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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 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> ToOwned for T
where T: Clone,

Source§

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

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

§

impl<A> SpecEq<&A> for A
where A: ?Sized,

§

impl<A> SpecEq<&mut A> for A
where A: ?Sized,

§

impl<A> SpecEq<A> for A
where A: ?Sized,

§

impl<A> SpecEq<Ghost<A>> for A

§

impl<A> SpecEq<Tracked<A>> for A