Skip to main content

Codec

Trait Codec 

Source
pub trait Codec: Sized {
    type Rust;
    type Repr: Repr;

    // Required methods
    fn into_lean(value: Self::Rust) -> Value<Self>;
    fn to_lean(value: &Self::Rust) -> Value<Self>;
    fn from_lean(value: Value<Self>) -> Self::Rust;

    // Provided method
    fn lend<R>(value: &Value<Self>, f: impl FnOnce(&Self::Rust) -> R) -> R { ... }
}
Expand description

A conversion between a Rust type and the Lean type the implementor stands for.

Required Associated Types§

Source

type Rust

The Rust type that owns a value.

Source

type Repr: Repr

How Lean passes a value of the type.

Required Methods§

Source

fn into_lean(value: Self::Rust) -> Value<Self>

The Lean value of a Rust value that is given up. What can move is moved.

Source

fn to_lean(value: &Self::Rust) -> Value<Self>

The Lean value of a Rust value that stays with the caller. A copy.

Source

fn from_lean(value: Value<Self>) -> Self::Rust

The Rust value of a Lean value. What nothing else refers to is taken out of it, and the rest is copied.

A codec whose representation is a scalar must accept every value of that scalar here, since Value::from_scalar makes a value of it from any.

Provided Methods§

Source

fn lend<R>(value: &Value<Self>, f: impl FnOnce(&Self::Rust) -> R) -> R

Calls f with the Rust form of a Lean value that is only lent: the lender keeps its reference. This is how a Rust function bound to a Lean declaration receives an argument that Lean passes with @&.

The default copies the value out for the length of the call. A codec whose Lean object holds the Rust value lends that value itself.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Codec for Bool

Source§

impl Codec for ByteArray

Source§

impl Codec for Char

Source§

impl Codec for Float

Source§

impl Codec for Float32

Source§

impl Codec for FloatArray

Source§

impl Codec for ISize

Source§

impl Codec for Int

Source§

impl Codec for Int8

Source§

impl Codec for Int16

Source§

impl Codec for Int32

Source§

impl Codec for Int64

Source§

impl Codec for Nat

Source§

impl Codec for String

Source§

impl Codec for UInt8

Source§

impl Codec for UInt16

Source§

impl Codec for UInt32

Source§

impl Codec for UInt64

Source§

impl Codec for USize

Source§

impl Codec for Unit

Source§

impl<'a, const N: usize> Codec for Generic<'a, N>

Source§

type Rust = Generic<'a, N>

Source§

type Repr = Obj

Source§

impl<A: Codec, B: Codec> Codec for Prod<A, B>

Source§

type Rust = (<A as Codec>::Rust, <B as Codec>::Rust)

Source§

type Repr = Obj

Source§

impl<C: Codec, P: Primitive<Lean = C::Rust>> Codec for Via<C, P>

Source§

type Rust = <P as Primitive>::Rust

Source§

type Repr = <C as Codec>::Repr

Source§

impl<C: Codec> Codec for Array<C>

Source§

type Rust = Vec<<C as Codec>::Rust>

Source§

type Repr = Obj

Source§

impl<C: Codec> Codec for Boxed<C>

Source§

type Rust = Box<<C as Codec>::Rust>

Source§

type Repr = <C as Codec>::Repr

Source§

impl<C: Codec> Codec for List<C>

Source§

type Rust = Vec<<C as Codec>::Rust>

Source§

type Repr = Obj

Source§

impl<C: Codec> Codec for Option<C>

Source§

impl<E: Codec, A: Codec> Codec for Except<E, A>

Source§

type Rust = Result<<A as Codec>::Rust, <E as Codec>::Rust>

Source§

type Repr = Obj

Source§

impl<T: Clone + 'static> Codec for Opaque<T>

Source§

impl<W: Word> Codec for BitVec<W>