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§
Required Methods§
Sourcefn into_lean(value: Self::Rust) -> Value<Self>
fn into_lean(value: Self::Rust) -> Value<Self>
The Lean value of a Rust value that is given up. What can move is moved.
Sourcefn to_lean(value: &Self::Rust) -> Value<Self>
fn to_lean(value: &Self::Rust) -> Value<Self>
The Lean value of a Rust value that stays with the caller. A copy.
Sourcefn from_lean(value: Value<Self>) -> Self::Rust
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§
Sourcefn lend<R>(value: &Value<Self>, f: impl FnOnce(&Self::Rust) -> R) -> R
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".