pub struct Star<A>(pub A);Expand description
Kleene star combinator: greedy zero-or-more repetition, consuming/producing Seq<A::PVal>.
Parsing semantics: always succeeds (may return an empty sequence). Stops when A fails or
consumes zero bytes.
§Consistency
A sequence s is consistent with Star<A> iff every element of s is consistent with A.
§Note
This combinator is mostly used internally to specify Repeat<A, B>, which is
able to disambiguate A and B and hence more compositional.
Tuple Fields§
§0: AImplementations§
Source§impl<A: SpecParser> Star<A>
impl<A: SpecParser> Star<A>
Sourcepub open spec fn parse_rec(&self, ibuf: Seq<u8>) -> (int, Seq<A::PVal>)
pub open spec fn parse_rec(&self, ibuf: Seq<u8>) -> (int, Seq<A::PVal>)
{
match self.0.spec_parse(ibuf) {
Some((n, v)) if 0 < n <= ibuf.len() => {
let (n_rest, vs) = self.parse_rec(ibuf.skip(n));
(n + n_rest, seq![v] + vs)
}
_ => (0, Seq::empty()),
}
}Recursive helper function for parsing.
Since Star always succeeds, this function is total.
Source§impl<A: SpecByteLen> Star<A>
impl<A: SpecByteLen> Star<A>
Sourcepub proof fn lemma_byte_len_cons(&self, v: A::T, vs: Seq<A::T>)
pub proof fn lemma_byte_len_cons(&self, v: A::T, vs: Seq<A::T>)
ensures
self.byte_len(seq![v] + vs) == self.0.byte_len(v) + self.byte_len(vs),Source§impl<A: SpecSerializer + Copy> Star<A>
impl<A: SpecSerializer + Copy> Star<A>
Sourcepub proof fn lemma_spec_serialize_cons(&self, first: A::SVal, rest: Seq<A::SVal>)
pub proof fn lemma_spec_serialize_cons(&self, first: A::SVal, rest: Seq<A::SVal>)
ensures
self.spec_serialize(seq![first] + rest)
== self.0.spec_serialize(first) + self.spec_serialize(rest),Serializing a nonempty sequence is the serialization of its first value followed by the serialization of the remaining values.
Sourcepub proof fn lemma_spec_serialize_suffix_step(&self, vs: Seq<A::SVal>, i: int)
pub proof fn lemma_spec_serialize_suffix_step(&self, vs: Seq<A::SVal>, i: int)
requires
0 <= i < vs.len(),ensuresself.spec_serialize(vs.skip(i))
== self.0.spec_serialize(vs[i]) + self.spec_serialize(vs.skip(i + 1)),Decomposes the serialization suffix beginning at i.
Source§impl<A: SpecSerializerDps> Star<A>
impl<A: SpecSerializerDps> Star<A>
Sourcepub open spec fn rfold_serialize_dps(&self, vs: Seq<A::SValue>, obuf: Seq<u8>) -> Seq<u8>
pub open spec fn rfold_serialize_dps(&self, vs: Seq<A::SValue>, obuf: Seq<u8>) -> Seq<u8>
{ vs.fold_right_alt(|elem, buf| self.0.spec_serialize_dps(elem, buf), obuf) }Trait Implementations§
Source§impl<A> Consistency for Star<A>where
A: Consistency,
impl<A> Consistency for Star<A>where
A: Consistency,
Source§open spec fn consistent(&self, vs: Self::Val) -> bool
open spec fn consistent(&self, vs: Self::Val) -> bool
{ forall |i: int| 0 <= i < vs.len() ==> self.0.consistent(#[trigger] vs[i]) }Source§type Val = Seq<<A as Consistency>::Val>
type Val = Seq<<A as Consistency>::Val>
The type of values whose consistency is being checked.
Source§impl<A, T> DerOrd<Vec<T>> for Star<A>
Available on crate feature alloc only.
impl<A, T> DerOrd<Vec<T>> for Star<A>
Available on crate feature
alloc only.Source§proof fn lemma_der_serialize_len(&self, vs: Seq<T::V>)
proof fn lemma_der_serialize_len(&self, vs: Seq<T::V>)
Source§open spec fn der_remaining(&self, vs: Seq<T::V>, state: StarDerState<A::State>) -> Seq<u8>
open spec fn der_remaining(&self, vs: Seq<T::V>, state: StarDerState<A::State>) -> Seq<u8>
{
if state.index < vs.len() {
self.0.der_remaining(vs[state.index as int], state.current)
+ Star(self.0).spec_serialize(vs.skip(state.index as int + 1))
} else {
Seq::empty()
}
}Source§open spec fn der_state_valid(&self, vs: Seq<T::V>, state: StarDerState<A::State>) -> bool
open spec fn der_state_valid(&self, vs: Seq<T::V>, state: StarDerState<A::State>) -> bool
{
&&& state.index <= vs.len()
&&& state.index < vs.len()
==> { self.0.der_state_valid(vs[state.index as int], state.current) }
}Source§impl<A> EquivSerializers for Star<A>where
A: EquivSerializersGeneral,
impl<A> EquivSerializers for Star<A>where
A: EquivSerializersGeneral,
Source§impl<A> EquivSerializersGeneral for Star<A>where
A: EquivSerializersGeneral,
impl<A> EquivSerializersGeneral for Star<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 Star<A>
impl<A: GoodSerializer> GoodSerializer for Star<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<A: NonMalleable + SafeParser> NonMalleable for Star<A>
impl<A: NonMalleable + SafeParser> NonMalleable for Star<A>
Source§open spec fn nonmal_inv(&self) -> bool
open spec fn nonmal_inv(&self) -> bool
{
&&& self.0.nonmal_inv()
&&& self.0.safe_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 Star<A>where
A: NonTailFmt,
impl<A> NonTailFmt for Star<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, vs: Self::SValue, obuf: Seq<u8>)
proof fn lemma_serialize_dps_prepend(&self, vs: Self::SValue, obuf: Seq<u8>)
Source§proof fn lemma_serialize_dps_len(&self, vs: Self::SValue, obuf: Seq<u8>)
proof fn lemma_serialize_dps_len(&self, vs: Self::SValue, obuf: Seq<u8>)
Source§impl<A: SafeParser> Productive for Star<A>
impl<A: SafeParser> Productive for Star<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 Star<A>where
A: SafeParser,
impl<A> SafeParser for Star<A>where
A: SafeParser,
Source§impl<Output: OutputBuf, Inner, T> Serializer<Output, [T]> for Star<Inner>where
T: DeepView,
Inner: Serializer<Output, T>,
impl<Output: OutputBuf, Inner, T> Serializer<Output, [T]> for Star<Inner>where
T: DeepView,
Inner: Serializer<Output, T>,
Source§exec fn serialize_into(&self, v: &[T], obuf: &mut Output)
exec fn serialize_into(&self, v: &[T], obuf: &mut Output)
Source§impl<A> SoundParser for Star<A>where
A: SoundParser,
impl<A> SoundParser for Star<A>where
A: SoundParser,
Source§impl<A: SpecByteLen> SpecByteLen for Star<A>
impl<A: SpecByteLen> SpecByteLen for Star<A>
Source§impl<A: SpecParser> SpecParser for Star<A>
impl<A: SpecParser> SpecParser for Star<A>
Source§impl<A> SpecSerializer for Star<A>where
A: SpecSerializer,
impl<A> SpecSerializer for Star<A>where
A: SpecSerializer,
Source§open spec fn spec_serialize(&self, vs: Self::SVal) -> Seq<u8>
open spec fn spec_serialize(&self, vs: Self::SVal) -> Seq<u8>
{ spec_serialize_seq(&self.0, vs) }Source§type SVal = Seq<<A as SpecSerializer>::SVal>
type SVal = Seq<<A as SpecSerializer>::SVal>
The type of values to be serialized.
Source§impl<A> SpecSerializerDps for Star<A>where
A: SpecSerializerDps,
impl<A> SpecSerializerDps for Star<A>where
A: SpecSerializerDps,
Source§impl<A: ValueByteLen> ValueByteLen for Star<A>
impl<A: ValueByteLen> ValueByteLen for Star<A>
Source§open spec fn value_byte_len(v: Self::T) -> nat
open spec fn value_byte_len(v: Self::T) -> nat
{ v.fold_left(0, |acc: nat, elem| acc + A::value_byte_len(elem)) }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 Star<A>
Auto Trait Implementations§
impl<A> Freeze for Star<A>where
A: Freeze,
impl<A> RefUnwindSafe for Star<A>where
A: RefUnwindSafe,
impl<A> Send for Star<A>where
A: Send,
impl<A> Sync for Star<A>where
A: Sync,
impl<A> Unpin for Star<A>where
A: Unpin,
impl<A> UnsafeUnpin for Star<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for Star<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