pub trait Primitive {
type Lean;
type Rust;
// Required methods
fn to_lean(value: &Self::Rust) -> Self::Lean;
fn from_lean(value: Self::Lean) -> Self::Rust;
// Provided method
fn into_lean(value: Self::Rust) -> Self::Lean { ... }
}Expand description
A primitive type of your own: a Rust type of your choice in place of the one inlean gives a Lean type.
Signatures and generated types then use Primitive::Rust, with no conversion left to
the caller. The trait is implemented for a marker type, so the Rust type can come from any
crate. To have a 256-bit integer of a library stand for BitVec 256:
pub struct U256Primitive;
impl inlean_runtime::Primitive for U256Primitive {
type Lean = [u64; 4]; // what inlean uses for `BitVec 256`
type Rust = U256;
fn to_lean(value: &U256) -> [u64; 4] {
value.0
}
fn from_lean(limbs: [u64; 4]) -> U256 {
U256(limbs)
}
}and name the marker in Cargo.toml, by a path that starts with crate:: or :::
[package.metadata.inlean.types]
"BitVec 256" = "crate::U256Primitive"Both functions must be total, and a value that goes to Lean and comes back must be the same value: a function written in Lean is proved for every value of its Lean types, and that is only worth something if every Rust value is one of them.
Required Associated Types§
Required Methods§
Sourcefn to_lean(value: &Self::Rust) -> Self::Lean
fn to_lean(value: &Self::Rust) -> Self::Lean
The default type’s value of a value that stays with the caller.
fn from_lean(value: Self::Lean) -> Self::Rust
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".