Skip to main content

FnSerializer

Struct FnSerializer 

Source
pub struct FnSerializer<Output: OutputBuf, T: DeepView + ?Sized, Spec: SpecByteLen<T = T::V> + SpecSerializer<SVal = T::V> + Consistency<Val = T::V>, Exec: Fn(&T, &mut Output)> {
    pub exec_fn: Exec,
    pub spec_fn: Ghost<Spec>,
    pub _output: PhantomData<Output>,
    pub _marker: PhantomData<T>,
}
Expand description

Pairs an executable serializer closure with a ghost specification serializer.

Fields§

§exec_fn: Exec§spec_fn: Ghost<Spec>§_output: PhantomData<Output>§_marker: PhantomData<T>

Implementations§

Source§

impl<Output, T, Spec, Exec> FnSerializer<Output, T, Spec, Exec>
where Output: OutputBuf, T: DeepView + ?Sized, Spec: SpecByteLen<T = T::V> + SpecSerializer<SVal = T::V> + Consistency<Val = T::V>, Exec: Fn(&T, &mut Output),

Source

pub exec fn new(exec_fn: Exec, Ghost(spec_fn): Ghost<Spec>) -> serializer : Self

requires
forall |v: &T, obuf: &mut Output| {
    (spec_fn.consistent(v.deep_view()) && obuf.fits(spec_fn.byte_len(v.deep_view())))
        ==> #[trigger] call_requires(exec_fn, (v, obuf))
},
forall |v: &T, obuf: &mut Output| {
    (spec_fn.consistent(v.deep_view()) && #[trigger]
        call_ensures(exec_fn, (v, obuf), ()))
        ==> {
            &&& final(obuf)@ == obuf@ + spec_fn.spec_serialize(v.deep_view())
            &&& forall |n| {
                #[trigger] obuf.fits(spec_fn.byte_len(v.deep_view()) + n)
                    <==> final(obuf).fits(n)
            }
            &&& obuf.same_destination(final(obuf))

        }
},
ensures
serializer.exec_inv(),
serializer.spec_fn == spec_fn,

Trait Implementations§

Source§

impl<Output, T, Spec, Exec> Consistency for FnSerializer<Output, T, Spec, Exec>
where Output: OutputBuf, T: DeepView + ?Sized, Spec: SpecByteLen<T = T::V> + SpecSerializer<SVal = T::V> + Consistency<Val = T::V>, Exec: Fn(&T, &mut Output),

Source§

open spec fn consistent(&self, v: Self::Val) -> bool

{
    let Ghost(spec_fn) = self.spec_fn;
    spec_fn.consistent(v)
}
Source§

type Val = <T as DeepView>::V

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

impl<Output, T, Spec, Exec> GoodSerializer for FnSerializer<Output, T, Spec, Exec>
where Output: OutputBuf, T: DeepView + ?Sized, Spec: GoodSerializer<T = T::V> + Consistency<Val = T::V>, Exec: Fn(&T, &mut Output),

Source§

open spec fn serialize_inv(&self) -> bool

{
    let Ghost(spec_fn) = self.spec_fn;
    spec_fn.serialize_inv()
}
Source§

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

Source§

impl<Output, T, Spec, Exec> Serializer<Output, T> for FnSerializer<Output, T, Spec, Exec>
where Output: OutputBuf, T: DeepView + ?Sized, Spec: SpecByteLen<T = T::V> + SpecSerializer<SVal = T::V> + Consistency<Val = T::V>, Exec: Fn(&T, &mut Output),

Source§

open spec fn exec_inv(&self) -> bool

{
    let Ghost(spec_fn) = self.spec_fn;
    &&& forall |v: &T, obuf: &mut Output| {
        (spec_fn.consistent(v.deep_view()) && obuf.fits(spec_fn.byte_len(v.deep_view())))
            ==> #[trigger] call_requires(self.exec_fn, (v, obuf))
    }
    &&& forall |v: &T, obuf: &mut Output| {
        (spec_fn.consistent(v.deep_view()) && #[trigger]
            call_ensures(self.exec_fn, (v, obuf), ()))
            ==> {
                &&& final(obuf)@ == obuf@ + spec_fn.spec_serialize(v.deep_view())
                &&& forall |n| {
                    #[trigger] obuf.fits(spec_fn.byte_len(v.deep_view()) + n)
                        <==> final(obuf).fits(n)
                }
                &&& obuf.same_destination(final(obuf))

            }
    }

}
Source§

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

Source§

impl<Output, T, Spec, Exec> SpecByteLen for FnSerializer<Output, T, Spec, Exec>
where Output: OutputBuf, T: DeepView + ?Sized, Spec: SpecByteLen<T = T::V> + SpecSerializer<SVal = T::V> + Consistency<Val = T::V>, Exec: Fn(&T, &mut Output),

Source§

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

{
    let Ghost(spec_fn) = self.spec_fn;
    spec_fn.byte_len(v)
}
Source§

type T = <T as DeepView>::V

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

impl<Output, T, Spec, Exec> SpecSerializer for FnSerializer<Output, T, Spec, Exec>
where Output: OutputBuf, T: DeepView + ?Sized, Spec: SpecByteLen<T = T::V> + SpecSerializer<SVal = T::V> + Consistency<Val = T::V>, Exec: Fn(&T, &mut Output),

Source§

open spec fn spec_serialize(&self, v: Self::SVal) -> Seq<u8>

{
    let Ghost(spec_fn) = self.spec_fn;
    spec_fn.spec_serialize(v)
}
Source§

type SVal = <T as DeepView>::V

The type of values to be serialized.

Auto Trait Implementations§

§

impl<Output, T, Spec, Exec> Freeze for FnSerializer<Output, T, Spec, Exec>
where Exec: Freeze, T: ?Sized,

§

impl<Output, T, Spec, Exec> RefUnwindSafe for FnSerializer<Output, T, Spec, Exec>
where Exec: RefUnwindSafe, Output: RefUnwindSafe, T: RefUnwindSafe + ?Sized, Spec: RefUnwindSafe,

§

impl<Output, T, Spec, Exec> Send for FnSerializer<Output, T, Spec, Exec>
where Exec: Send, Output: Send, T: Send + ?Sized,

§

impl<Output, T, Spec, Exec> Sync for FnSerializer<Output, T, Spec, Exec>
where Exec: Sync, Output: Sync, T: Sync + ?Sized,

§

impl<Output, T, Spec, Exec> Unpin for FnSerializer<Output, T, Spec, Exec>
where Exec: Unpin, Output: Unpin, T: Unpin + ?Sized, Spec: Unpin,

§

impl<Output, T, Spec, Exec> UnsafeUnpin for FnSerializer<Output, T, Spec, Exec>
where Exec: UnsafeUnpin, T: ?Sized,

§

impl<Output, T, Spec, Exec> UnwindSafe for FnSerializer<Output, T, Spec, Exec>
where Exec: UnwindSafe, Output: UnwindSafe, T: UnwindSafe + ?Sized, Spec: 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> 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, S> SerializerExt<T> for S
where S: SpecByteLen<T = <T as DeepView>::V> + SpecSerializer<SVal = <T as DeepView>::V> + Consistency<Val = <T as DeepView>::V>, T: DeepView + ?Sized,

Source§

fn serialize<'a>(&self, v: &T, obuf: &'a mut [u8])
where Self: Serializer<OutputSlice<'a>, T>,

Source§

fn serialize_with_vec(&self, v: &T, obuf: &mut Vec<u8>)
where Self: Serializer<Vec<u8>, T>,

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