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: ATrait Implementations§
Source§impl<A> Consistency for Opt<A>where
A: Consistency,
impl<A> Consistency for Opt<A>where
A: Consistency,
Source§impl<A, T> DerOrd<Option<T>> for Opt<A>where
T: DeepView,
A: DerOrd<T>,
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>)
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>
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
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§impl<A> EquivSerializers for Opt<A>where
A: EquivSerializers,
impl<A> EquivSerializers for Opt<A>where
A: EquivSerializers,
Source§impl<A> EquivSerializersGeneral for Opt<A>where
A: EquivSerializersGeneral,
impl<A> EquivSerializersGeneral for Opt<A>where
A: EquivSerializersGeneral,
Source§open spec fn equiv_general_inv(&self) -> bool
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>)
proof fn lemma_serialize_equiv(&self, v: Self::SVal, obuf: Seq<u8>)
Source§impl<A: GoodSerializer> GoodSerializer for Opt<A>
impl<A: GoodSerializer> GoodSerializer for Opt<A>
Source§open spec fn serialize_inv(&self) -> bool
open spec fn serialize_inv(&self) -> bool
{ self.0.serialize_inv() }Source§proof fn lemma_serialize_len(&self, v: Self::SVal)
proof fn lemma_serialize_len(&self, v: Self::SVal)
Source§impl<Inner: MinMaxByteLen> MinMaxByteLen for Opt<Inner>
impl<Inner: MinMaxByteLen> MinMaxByteLen for Opt<Inner>
Source§impl<A: NonMalleable> NonMalleable for Opt<A>
impl<A: NonMalleable> NonMalleable for Opt<A>
Source§open spec fn nonmal_inv(&self) -> bool
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>)
proof fn lemma_parse_non_malleable(&self, buf1: Seq<u8>, buf2: Seq<u8>)
Source§impl<A> NonTailFmt for Opt<A>where
A: NonTailFmt,
impl<A> NonTailFmt for Opt<A>where
A: NonTailFmt,
Source§open spec fn serialize_dps_inv(&self) -> bool
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>)
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>)
proof fn lemma_serialize_dps_len(&self, v: Self::SValue, obuf: Seq<u8>)
Source§impl<A: SafeParser> Productive for Opt<A>
impl<A: SafeParser> Productive for Opt<A>
Source§open spec fn productive_inv(&self) -> bool
open spec fn productive_inv(&self) -> bool
{ false }Source§proof fn lemma_productive(&self, s: Seq<u8>)
proof fn lemma_productive(&self, s: Seq<u8>)
Source§impl<A> SafeParser for Opt<A>where
A: SafeParser,
impl<A> SafeParser for Opt<A>where
A: SafeParser,
Source§impl<Output: OutputBuf, A, T> Serializer<Output, Option<T>> for Opt<A>where
T: DeepView,
A: Serializer<Output, T>,
impl<Output: OutputBuf, A, T> Serializer<Output, Option<T>> for Opt<A>where
T: DeepView,
A: Serializer<Output, T>,
Source§exec fn serialize_into(&self, v: &Option<T>, obuf: &mut Output)
exec fn serialize_into(&self, v: &Option<T>, obuf: &mut Output)
Source§impl<A> SoundParser for Opt<A>where
A: SoundParser,
impl<A> SoundParser for Opt<A>where
A: SoundParser,
Source§impl<Inner: SpecByteLen> SpecByteLen for Opt<Inner>
impl<Inner: SpecByteLen> SpecByteLen for Opt<Inner>
Source§impl<A> SpecParser for Opt<A>where
A: SpecParser,
impl<A> SpecParser for Opt<A>where
A: SpecParser,
Source§impl<A> SpecSerializer for Opt<A>where
A: SpecSerializer,
impl<A> SpecSerializer for Opt<A>where
A: SpecSerializer,
Source§impl<A> SpecSerializerDps for Opt<A>where
A: SpecSerializerDps,
impl<A> SpecSerializerDps for Opt<A>where
A: SpecSerializerDps,
Source§impl<Inner: ValueByteLen> ValueByteLen for Opt<Inner>
impl<Inner: ValueByteLen> ValueByteLen for Opt<Inner>
Source§open spec fn value_byte_len(v: Self::T) -> nat
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)
proof fn lemma_value_len_matches_byte_len(&self, v: Self::T)
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more