pub struct Alt<A, B, const NONDETERMINISTIC: bool = false>(pub A, pub B);Expand description
Ordered alternative combinator.
Parsing semantics: like Choice, but both branches consume/produce the same type.
The result is returned directly without a Sum wrapper.
Serialization semantics: if only one branch is consistent with a value, that branch is used. If both branches are consistent, serialization is intentionally underspecified and may use either branch.
§Consistency
A value v is consistent with Alt(A, B) iff it is consistent with A OR B.
§Unambiguity
Requires disjoint_domains(A, B).
§Malleability
This combinator introduces malleability by default.
Non-malleability can be recovered if A is disjoint from B (see disjoint_values).
Tuple Fields§
§0: A§1: BImplementations§
Source§impl<const NONDETERMINISTIC: bool, A, B> Alt<A, B, NONDETERMINISTIC>
impl<const NONDETERMINISTIC: bool, A, B> Alt<A, B, NONDETERMINISTIC>
Sourcepub open spec fn choose_left(&self, v: A::Val) -> bool
pub open spec fn choose_left(&self, v: A::Val) -> bool
{
if NONDETERMINISTIC {
arbitrary_or_left(self.0.consistent(v), self.1.consistent(v))
} else {
self.0.consistent(v)
}
}For non-deterministic Alt:
If exactly one branch accepts v, this returns that branch.
If both accept v, the choice is unspecified.
For deterministic Alt, this returns true iff the left branch accepts v.
Trait Implementations§
Source§impl<const NONDETERMINISTIC: bool, A: Consistency, B: Consistency<Val = A::Val>> Consistency for Alt<A, B, NONDETERMINISTIC>
impl<const NONDETERMINISTIC: bool, A: Consistency, B: Consistency<Val = A::Val>> Consistency for Alt<A, B, NONDETERMINISTIC>
Source§open spec fn consistent(&self, v: Self::Val) -> bool
open spec fn consistent(&self, v: Self::Val) -> bool
{ self.0.consistent(v) || self.1.consistent(v) }Source§type Val = <A as Consistency>::Val
type Val = <A as Consistency>::Val
Source§impl<const NONDETERMINISTIC: bool, A, B> EquivSerializers for Alt<A, B, NONDETERMINISTIC>where
A: EquivSerializers + Consistency<Val = A::SVal>,
B: EquivSerializers<SVal = A::SVal> + Consistency<Val = B::SVal>,
impl<const NONDETERMINISTIC: bool, A, B> EquivSerializers for Alt<A, B, NONDETERMINISTIC>where
A: EquivSerializers + Consistency<Val = A::SVal>,
B: EquivSerializers<SVal = A::SVal> + Consistency<Val = B::SVal>,
Source§impl<const NONDETERMINISTIC: bool, A, B> EquivSerializersGeneral for Alt<A, B, NONDETERMINISTIC>where
A: EquivSerializersGeneral + Consistency<Val = A::SVal>,
B: EquivSerializersGeneral<SVal = A::SVal> + Consistency<Val = B::SVal>,
impl<const NONDETERMINISTIC: bool, A, B> EquivSerializersGeneral for Alt<A, B, NONDETERMINISTIC>where
A: EquivSerializersGeneral + Consistency<Val = A::SVal>,
B: EquivSerializersGeneral<SVal = A::SVal> + Consistency<Val = B::SVal>,
Source§open spec fn equiv_general_inv(&self) -> bool
open spec fn equiv_general_inv(&self) -> bool
{
&&& self.0.equiv_general_inv()
&&& self.1.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<const NONDETERMINISTIC: bool, A, B> GoodSerializer for Alt<A, B, NONDETERMINISTIC>where
A: GoodSerializer + Consistency<Val = A::SVal>,
B: GoodSerializer<T = A::T> + Consistency<Val = B::SVal>,
impl<const NONDETERMINISTIC: bool, A, B> GoodSerializer for Alt<A, B, NONDETERMINISTIC>where
A: GoodSerializer + Consistency<Val = A::SVal>,
B: GoodSerializer<T = A::T> + Consistency<Val = B::SVal>,
Source§open spec fn serialize_inv(&self) -> bool
open spec fn serialize_inv(&self) -> bool
{
&&& self.0.serialize_inv()
&&& self.1.serialize_inv()
}Source§proof fn lemma_serialize_len(&self, v: Self::SVal)
proof fn lemma_serialize_len(&self, v: Self::SVal)
Source§impl<const NONDETERMINISTIC: bool, Left: HasAsn1Start, Right: HasAsn1Start<PVal = Left::PVal>> HasAsn1Start for Alt<Left, Right, NONDETERMINISTIC>
Ordered alternatives have the same accepted start union as structural choices.
impl<const NONDETERMINISTIC: bool, Left: HasAsn1Start, Right: HasAsn1Start<PVal = Left::PVal>> HasAsn1Start for Alt<Left, Right, NONDETERMINISTIC>
Ordered alternatives have the same accepted start union as structural choices.
Source§open spec fn asn1_start(&self) -> Asn1StartDomain
open spec fn asn1_start(&self) -> Asn1StartDomain
{ asn1_start_union(self.0.asn1_start(), self.1.asn1_start()) }Source§proof fn lemma_parse_implies_asn1_start(&self, input: Seq<u8>)
proof fn lemma_parse_implies_asn1_start(&self, input: Seq<u8>)
Source§impl<const NONDETERMINISTIC: bool, A, B> MinMaxByteLen for Alt<A, B, NONDETERMINISTIC>
impl<const NONDETERMINISTIC: bool, A, B> MinMaxByteLen for Alt<A, B, NONDETERMINISTIC>
Source§impl<const NONDETERMINISTIC: bool, A, B> NoLookAhead for Alt<A, B, NONDETERMINISTIC>
impl<const NONDETERMINISTIC: bool, A, B> NoLookAhead for Alt<A, B, NONDETERMINISTIC>
Source§open spec fn no_lookahead_inv(&self) -> bool
open spec fn no_lookahead_inv(&self) -> bool
{
&&& self.0.no_lookahead_inv()
&&& self.1.no_lookahead_inv()
&&& disjoint_domains(self.0, self.1)
}Source§proof fn lemma_no_lookahead(&self, i1: Seq<u8>, i2: Seq<u8>)
proof fn lemma_no_lookahead(&self, i1: Seq<u8>, i2: Seq<u8>)
Source§impl<const NONDETERMINISTIC: bool, A, B> NonMalleable for Alt<A, B, NONDETERMINISTIC>
impl<const NONDETERMINISTIC: bool, A, B> NonMalleable for Alt<A, B, NONDETERMINISTIC>
Source§open spec fn nonmal_inv(&self) -> bool
open spec fn nonmal_inv(&self) -> bool
{
&&& self.0.sound_inv()
&&& self.1.sound_inv()
&&& self.0.nonmal_inv()
&&& self.1.nonmal_inv()
&&& disjoint_values(self.0, self.1)
}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<const NONDETERMINISTIC: bool, A, B> NonTailFmt for Alt<A, B, NONDETERMINISTIC>where
A: NonTailFmt + Consistency<Val = A::SValue>,
B: NonTailFmt<T = A::T> + Consistency<Val = B::SValue>,
impl<const NONDETERMINISTIC: bool, A, B> NonTailFmt for Alt<A, B, NONDETERMINISTIC>where
A: NonTailFmt + Consistency<Val = A::SValue>,
B: NonTailFmt<T = A::T> + Consistency<Val = B::SValue>,
Source§open spec fn serialize_dps_inv(&self) -> bool
open spec fn serialize_dps_inv(&self) -> bool
{
&&& self.0.serialize_dps_inv()
&&& self.1.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<const NONDETERMINISTIC: bool, A, B> Productive for Alt<A, B, NONDETERMINISTIC>
impl<const NONDETERMINISTIC: bool, A, B> Productive for Alt<A, B, NONDETERMINISTIC>
Source§open spec fn productive_inv(&self) -> bool
open spec fn productive_inv(&self) -> bool
{
&&& self.0.productive_inv()
&&& self.1.productive_inv()
}Source§proof fn lemma_productive(&self, s: Seq<u8>)
proof fn lemma_productive(&self, s: Seq<u8>)
Source§impl<const NONDETERMINISTIC: bool, A: SPRoundTripDps, B: SPRoundTripDps<T = A::T>> SPRoundTripDps for Alt<A, B, NONDETERMINISTIC>
impl<const NONDETERMINISTIC: bool, A: SPRoundTripDps, B: SPRoundTripDps<T = A::T>> SPRoundTripDps for Alt<A, B, NONDETERMINISTIC>
Source§open spec fn unambiguous(&self) -> bool
open spec fn unambiguous(&self) -> bool
{
&&& self.0.unambiguous()
&&& self.1.unambiguous()
&&& disjoint_domains(self.0, self.1)
}Source§proof fn theorem_serialize_dps_parse_roundtrip(&self, v: Self::T, obuf: Seq<u8>)
proof fn theorem_serialize_dps_parse_roundtrip(&self, v: Self::T, obuf: Seq<u8>)
Source§impl<const NONDETERMINISTIC: bool, A, B> SafeParser for Alt<A, B, NONDETERMINISTIC>
impl<const NONDETERMINISTIC: bool, A, B> SafeParser for Alt<A, B, NONDETERMINISTIC>
Source§impl<const NONDETERMINISTIC: bool, A, B> SoundParser for Alt<A, B, NONDETERMINISTIC>
impl<const NONDETERMINISTIC: bool, A, B> SoundParser for Alt<A, B, NONDETERMINISTIC>
Source§impl<const NONDETERMINISTIC: bool, A, B> SpecByteLen for Alt<A, B, NONDETERMINISTIC>
impl<const NONDETERMINISTIC: bool, A, B> SpecByteLen for Alt<A, B, NONDETERMINISTIC>
Source§impl<const NONDETERMINISTIC: bool, A: SpecParser, B: SpecParser<PVal = A::PVal>> SpecParser for Alt<A, B, NONDETERMINISTIC>
impl<const NONDETERMINISTIC: bool, A: SpecParser, B: SpecParser<PVal = A::PVal>> SpecParser for Alt<A, B, NONDETERMINISTIC>
Source§impl<const NONDETERMINISTIC: bool, A, B> SpecSerializer for Alt<A, B, NONDETERMINISTIC>where
A: SpecSerializer + Consistency<Val = A::SVal>,
B: SpecSerializer<SVal = A::SVal> + Consistency<Val = B::SVal>,
impl<const NONDETERMINISTIC: bool, A, B> SpecSerializer for Alt<A, B, NONDETERMINISTIC>where
A: SpecSerializer + Consistency<Val = A::SVal>,
B: SpecSerializer<SVal = A::SVal> + Consistency<Val = B::SVal>,
Source§open spec fn spec_serialize(&self, v: Self::SVal) -> Seq<u8>
open spec fn spec_serialize(&self, v: Self::SVal) -> Seq<u8>
{ if self.choose_left(v) { self.0.spec_serialize(v) } else { self.1.spec_serialize(v) } }Source§type SVal = <A as SpecSerializer>::SVal
type SVal = <A as SpecSerializer>::SVal
Source§impl<const NONDETERMINISTIC: bool, A, B> SpecSerializerDps for Alt<A, B, NONDETERMINISTIC>where
A: SpecSerializerDps + Consistency<Val = A::SValue>,
B: SpecSerializerDps<SValue = A::SValue> + Consistency<Val = B::SValue>,
impl<const NONDETERMINISTIC: bool, A, B> SpecSerializerDps for Alt<A, B, NONDETERMINISTIC>where
A: SpecSerializerDps + Consistency<Val = A::SValue>,
B: SpecSerializerDps<SValue = A::SValue> + Consistency<Val = B::SValue>,
impl<A: Copy, B: Copy, const NONDETERMINISTIC: bool> Copy for Alt<A, B, NONDETERMINISTIC>
Auto Trait Implementations§
impl<A, B, const NONDETERMINISTIC: bool> Freeze for Alt<A, B, NONDETERMINISTIC>
impl<A, B, const NONDETERMINISTIC: bool> RefUnwindSafe for Alt<A, B, NONDETERMINISTIC>where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B, const NONDETERMINISTIC: bool> Send for Alt<A, B, NONDETERMINISTIC>
impl<A, B, const NONDETERMINISTIC: bool> Sync for Alt<A, B, NONDETERMINISTIC>
impl<A, B, const NONDETERMINISTIC: bool> Unpin for Alt<A, B, NONDETERMINISTIC>
impl<A, B, const NONDETERMINISTIC: bool> UnsafeUnpin for Alt<A, B, NONDETERMINISTIC>where
A: UnsafeUnpin,
B: UnsafeUnpin,
impl<A, B, const NONDETERMINISTIC: bool> UnwindSafe for Alt<A, B, NONDETERMINISTIC>where
A: UnwindSafe,
B: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T, VERUS_SPEC__A> FromSpec<T> for VERUS_SPEC__Awhere
VERUS_SPEC__A: From<T>,
impl<T, VERUS_SPEC__A> FromSpec<T> for VERUS_SPEC__Awhere
VERUS_SPEC__A: From<T>,
fn obeys_from_spec() -> bool
fn from_spec(v: T) -> VERUS_SPEC__A
§impl<T, VERUS_SPEC__A> IntoSpec<T> for VERUS_SPEC__Awhere
VERUS_SPEC__A: Into<T>,
impl<T, VERUS_SPEC__A> IntoSpec<T> for VERUS_SPEC__Awhere
VERUS_SPEC__A: Into<T>,
fn obeys_into_spec() -> bool
fn into_spec(self) -> T
§impl<T, U> IntoSpecImpl<U> for Twhere
U: From<T>,
impl<T, U> IntoSpecImpl<U> for Twhere
U: From<T>,
fn obeys_into_spec() -> bool
fn into_spec(self) -> U
Source§impl<C> NonAmbiguous for Cwhere
C: SPRoundTrip,
impl<C> NonAmbiguous for Cwhere
C: SPRoundTrip,
Source§open spec fn nonamb_inv(&self) -> bool
open spec fn nonamb_inv(&self) -> bool
{ self.sp_roundtrip_inv() }Source§proof fn lemma_serialize_injective(
&self,
v1: <C as Consistency>::Val,
v2: <C as Consistency>::Val,
)
proof fn lemma_serialize_injective( &self, v1: <C as Consistency>::Val, v2: <C as Consistency>::Val, )
Source§impl<C> PSRoundTrip for C
impl<C> PSRoundTrip for C
Source§open spec fn ps_roundtrip_inv(&self) -> bool
open spec fn ps_roundtrip_inv(&self) -> bool
{ self.safe_inv() && self.sound_inv() && self.nonmal_inv() && self.sp_roundtrip_inv() }Source§proof fn theorem_parse_serialize_roundtrip(&self, ibuf: Seq<u8>)
proof fn theorem_parse_serialize_roundtrip(&self, ibuf: Seq<u8>)
Source§impl<C> SPRoundTrip for C
impl<C> SPRoundTrip for C
Source§open spec fn sp_roundtrip_inv(&self) -> bool
open spec fn sp_roundtrip_inv(&self) -> bool
{ self.serialize_inv() && self.equiv_inv() && self.unambiguous() }