Skip to main content

Primitive

Trait Primitive 

Source
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§

Source

type Lean

The Rust type inlean gives the Lean type by default.

Source

type Rust

The type to use instead.

Required Methods§

Source

fn to_lean(value: &Self::Rust) -> Self::Lean

The default type’s value of a value that stays with the caller.

Source

fn from_lean(value: Self::Lean) -> Self::Rust

Provided Methods§

Source

fn into_lean(value: Self::Rust) -> Self::Lean

The default type’s value of a value that is given up. Implement it when the value owns something that can move into the result, such as a buffer; the default copies.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§