Skip to main content

DepCombinator

Trait DepCombinator 

Source
pub trait DepCombinator {
    type Key;
    type Val;
    type Body: Consistency<Val = Self::Val>;

    // Required methods
    spec fn apply(&self, key: Self::Key) -> Self::Body;
    spec fn recover(&self, value: Self::Val) -> Self::Key;
    proof fn lemma_recover_consistent(&self, key: Self::Key, value: Self::Val);

    // Provided method
    open spec fn recover_inv(&self) -> bool { ... }
}
Expand description

A family of dependent combinators indexed by a key type.

Used to constrain the Tail combinator in a Implicit<Head, Tail>.

Required Associated Types§

Source

type Key

The type of keys parsed by the head combinator/to be recovered during serialization.

Source

type Val

The type of values consumed/produced by the body combinator.

Source

type Body: Consistency<Val = Self::Val>

The type of the body combinator produced by apply.

Required Methods§

Source

spec fn apply(&self, key: Self::Key) -> Self::Body

Given a key, produce the body combinator for that key.

Source

spec fn recover(&self, value: Self::Val) -> Self::Key

Given a body value, recover the key used to produce the body combinator.

Source

proof fn lemma_recover_consistent(&self, key: Self::Key, value: Self::Val)

requires
self.recover_inv(),
ensures
self.apply(key).consistent(value) ==> self.recover(value) == key,

Recover must agree with any key that makes the body’s value consistent.

Provided Methods§

Source

open spec fn recover_inv(&self) -> bool

{ true }

Implementors§

Source§

impl<D1: DepCombinator, D2: DepCombinator> DepCombinator for Pair<D1, D2>

Source§

type Key = (<D1 as DepCombinator>::Key, <D2 as DepCombinator>::Key)

Source§

type Val = (<D1 as DepCombinator>::Val, <D2 as DepCombinator>::Val)

Source§

type Body = Pair<<D1 as DepCombinator>::Body, <D2 as DepCombinator>::Body>

Source§

impl<Head, Nested> DepCombinator for Implicit<Head, Nested>
where Head: Consistency, Nested: DepCombinator<Key = Head::Val>,

Source§

type Key = <Head as Consistency>::Val

Source§

type Val = <Nested as DepCombinator>::Val

Source§

type Body = <Nested as DepCombinator>::Body

Source§

impl<Key, Val, Body> DepCombinator for KVFormat<Key, Val, Body>
where Body: Consistency<Val = Val>,

Source§

type Key = Key

Source§

type Val = Val

Source§

type Body = Body

Source§

impl<Len, Then> DepCombinator for NBytesOf<Len, Then>
where Len: AsLen, Then: SpecByteLen + Consistency<Val = Then::T>,

Source§

type Key = Len

Source§

type Val = <Then as Consistency>::Val

Source§

type Body = ExactLen<Then, Len>

Source§

impl<Len: AsLen> DepCombinator for VariedLen<Len>

Source§

type Key = Len

Source§

type Val = Seq<u8>

Source§

type Body = Varied<Len>

Source§

impl<Tag> DepCombinator for VoidTag<Tag>

Source§

impl<Tag, C, Rest> DepCombinator for TVOr<Tag, C, Rest>
where C: Consistency, Rest: DepCombinator<Key = Tag>,

Source§

type Key = Tag

Source§

type Val = Sum<<C as Consistency>::Val, <Rest as DepCombinator>::Val>

Source§

type Body = Choice<Cond<C>, <Rest as DepCombinator>::Body>

Source§

impl<Tag, C: Consistency> DepCombinator for TVLeaf<Tag, C>

Source§

type Key = Tag

Source§

type Val = <C as Consistency>::Val

Source§

type Body = Cond<C>

Source§

impl<Tag, Left, Right> DepCombinator for TagValNode<Tag, Left, Right>
where Left: DepCombinator<Key = Tag>, Right: DepCombinator<Key = Tag>,

Source§

type Key = Tag

Source§

type Val = Sum<<Left as DepCombinator>::Val, <Right as DepCombinator>::Val>

Source§

type Body = Choice<<Left as DepCombinator>::Body, <Right as DepCombinator>::Body>

Source§

impl<Tag, Len, V> DepCombinator for TLVal<Tag, Len, V>
where Len: AsLen, V: DepCombinator<Key = Tag>, V::Body: SpecByteLen<T = V::Val>,