Skip to main content

Star

Struct Star 

Source
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: A

Implementations§

Source§

impl<A: SpecParser> Star<A>

Source

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>

Source

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>

Source

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.

Source

pub proof fn lemma_spec_serialize_suffix_step(&self, vs: Seq<A::SVal>, i: int)

requires
0 <= i < vs.len(),
ensures
self.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>

Source

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<Inner, T> ByteLen<[T]> for Star<Inner>
where Inner: ByteLen<T>, T: DeepView,

Source§

open spec fn exec_inv(&self) -> bool

{ self.0.exec_inv() }
Source§

exec fn length(&self, v: &[T]) -> len : usize

Source§

impl<A: Clone> Clone for Star<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 Star<A>
where A: Consistency,

Source§

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>

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

impl<A, T> DerOrd<Vec<T>> for Star<A>
where T: DeepView, A: DerOrd<T> + Copy,

Available on crate feature alloc only.
Source§

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>

{
    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

{
    &&& state.index <= vs.len()
    &&& state.index < vs.len()
        ==> { self.0.der_state_valid(vs[state.index as int], state.current) }

}
Source§

exec fn der_start(&self, v: &Vec<T>) -> state : StarDerState<A::State>

Source§

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

Source§

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

Source§

impl<A: DerState> DerState for Star<A>

Source§

impl<A> EquivSerializers for Star<A>

Source§

open spec fn equiv_inv(&self) -> bool

{ self.0.equiv_general_inv() }
Source§

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

Source§

impl<A> EquivSerializersGeneral for Star<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 Star<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<A: NonMalleable + SafeParser> NonMalleable for Star<A>

Source§

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

Source§

impl<A> NonTailFmt for Star<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, vs: Self::SValue, obuf: Seq<u8>)

Source§

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

Source§

impl<I, Inner> Parser<I> for Star<Inner>
where I: InputBuf, Inner: Parser<I> + Productive,

Available on crate feature alloc only.
Source§

open spec fn exec_inv(&self) -> bool

{
    &&& self.0.exec_inv()
    &&& self.0.safe_inv()
    &&& self.0.productive_inv()

}
Source§

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

Source§

type PT = Vec<<Inner as Parser<I>>::PT>

Executable value returned by this parser.
Source§

impl<Inner, T> Prepare<[T]> for Star<Inner>
where Inner: Prepare<T>, T: DeepView,

Source§

open spec fn exec_inv(&self) -> bool

{ self.0.exec_inv() }
Source§

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

Source§

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

Source§

open spec fn productive_inv(&self) -> bool

{ false }
Source§

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

Source§

impl<A> SafeParser for Star<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, Inner, T> Serializer<Output, [T]> for Star<Inner>
where T: DeepView, Inner: Serializer<Output, T>,

Source§

open spec fn exec_inv(&self) -> bool

{ self.0.exec_inv() }
Source§

exec fn serialize_into(&self, v: &[T], obuf: &mut Output)

Source§

impl<A> SoundParser for Star<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<A: SpecByteLen> SpecByteLen for Star<A>

Source§

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

{ v.fold_left(0, |acc: nat, elem| acc + self.0.byte_len(elem)) }
Source§

type T = Seq<<A as SpecByteLen>::T>

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

impl<A: SpecParser> SpecParser for Star<A>

Source§

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

{
    let (n, vs) = self.parse_rec(ibuf);
    Some((n, vs))
}
Source§

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

The type of parsed values.
Source§

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

Source§

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>

The type of values to be serialized.
Source§

impl<A> SpecSerializerDps for Star<A>

Source§

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

{ self.rfold_serialize_dps(vs, obuf) }
Source§

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

The type of values to be serialized.
Source§

impl<A: ValueByteLen> ValueByteLen for Star<A>

Source§

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)

Source§

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