Skip to main content

AsLen

Trait AsLen 

Source
pub trait AsLen: Sized + Copy {
    // Required methods
    spec fn as_nat(self) -> nat;
    exec fn get(self) -> len : usize;
    spec fn as_self(n: nat) -> Self;
    proof fn lemma_lossless_casting(v: Self);
}
Expand description

Types that can serve as format length (or count) fields.

The spec-facing conversion is to nat, which is the natural domain for lengths in proofs. The exec-facing conversion is to usize, which is the natural domain for runtime indexing.

Required Methods§

Source

spec fn as_nat(self) -> nat

The mathematical length represented by this value.

Source

exec fn get(self) -> len : usize

ensures
len as nat == self.as_nat(),

The runtime length represented by this value.

Source

spec fn as_self(n: nat) -> Self

Construct from a nat.

Source

proof fn lemma_lossless_casting(v: Self)

ensures
Self::as_self(v.as_nat()) == v,

as_self(v.as_nat()) == v.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl AsLen for u8

Source§

open spec fn as_nat(self) -> nat

{ self as nat }
Source§

exec fn get(self) -> len : usize

Source§

open spec fn as_self(n: nat) -> Self

{ n as u8 }
Source§

proof fn lemma_lossless_casting(v: Self)

Source§

impl AsLen for u16

Source§

open spec fn as_nat(self) -> nat

{ self as nat }
Source§

exec fn get(self) -> len : usize

Source§

open spec fn as_self(n: nat) -> Self

{ n as u16 }
Source§

proof fn lemma_lossless_casting(v: Self)

Source§

impl AsLen for u32

Source§

open spec fn as_nat(self) -> nat

{ self as nat }
Source§

exec fn get(self) -> len : usize

Source§

open spec fn as_self(n: nat) -> Self

{ n as u32 }
Source§

proof fn lemma_lossless_casting(v: Self)

Source§

impl AsLen for u64

Source§

open spec fn as_nat(self) -> nat

{ self as nat }
Source§

exec fn get(self) -> len : usize

Source§

open spec fn as_self(n: nat) -> Self

{ n as u64 }
Source§

proof fn lemma_lossless_casting(v: Self)

Source§

impl AsLen for usize

Source§

open spec fn as_nat(self) -> nat

{ self as nat }
Source§

exec fn get(self) -> len : usize

Source§

open spec fn as_self(n: nat) -> Self

{ n as usize }
Source§

proof fn lemma_lossless_casting(v: Self)

Source§

impl<T: AsLen> AsLen for &T

Source§

open spec fn as_nat(self) -> nat

{ (*self).as_nat() }
Source§

exec fn get(self) -> len : usize

Source§

open spec fn as_self(n: nat) -> Self

{ &T::as_self(n) }
Source§

proof fn lemma_lossless_casting(v: Self)

Implementors§