Expand description
Conversions between Rust values and Lean values, chosen by the Lean type.
Several Lean types share one Rust type: Array α and List α are both Vec<T>, and
ByteArray and Array UInt8 are both Vec<u8>. A conversion therefore cannot be found
from the Rust type alone. Generated code names it instead, as a type that implements
Codec and mirrors the Lean type. Each type of this module stands for the Lean type of
the same name, so Array<Option<String>> converts a Vec<Option<String>> to and from a
Lean Array (Option String).
A conversion moves what it can. Codec::into_lean takes the Rust value and builds the
Lean value around its buffers. Codec::from_lean takes out of the Lean value whatever
nothing else refers to, as Lean’s own compiled code does when it takes a value apart.
Only Codec::to_lean, which leaves the Rust value with the caller, always copies.
The conversions are safe functions because of Value: a Lean value together with its
type and the one reference to it that the holder owns. The single unsafe claim at the
boundary is Value::from_raw, where generated code says what a Lean function returned.
Structs§
- Array
- Lean’s
Array αas aVec. - BitVec
- Lean’s
BitVec was the unsigned integer or the limbsW. Lean keeps a bit vector as the natural number it encodes, so a value crosses with one copy of its limbs, and one that is below 2^63 without an allocation. - Bool
- Lean’s
Bool. - Boxed
- A value that the Rust type keeps in a
Box, as recursive types must. - Byte
Array - Lean’s
ByteArray. The Lean object holds aVec<u8>, so a value moves both ways. - Char
- Lean’s
Char. - Except
- Lean’s
Except ε αas aResult. Lean names the error type first, Rust the value type. - Fields
- The fields of a constructor object whose reference the caller gives up. They are taken when nothing else refers to the object, and shared with it otherwise: the rule Lean’s compiled code follows when it takes a value apart.
- Float
- Lean’s
Float. - Float32
- Lean’s
Float32. - Float
Array - Lean’s
FloatArray. The Lean object holds aVec<f64>, so a value moves both ways. - Generic
- A value of a type that a declaration bound to Rust is generic in, as
crate::Generic: the Lean object, passed on as it is.Nis the type’s place among the declaration’s type parameters. - ISize
- Lean’s
ISize. - Int
- Lean’s
Intascrate::Int, which is the Lean object itself where nothing else holds the object, and a copy of it otherwise. - Int8
- Lean’s
Int8. - Int16
- Lean’s
Int16. - Int32
- Lean’s
Int32. - Int64
- Lean’s
Int64. - List
- Lean’s
List αas aVec. - Nat
- Lean’s
Natascrate::Nat, which is the Lean object itself where nothing else holds the object, and a copy of it otherwise. - Opaque
- A type the block declares
opaque. Lean cannot look inside a value of it or make one, so nothing is converted: the value is the Rust value itself, in an object. It moves into Lean and moves back out. A value the caller keeps is cloned, and so is one that Lean still holds somewhere else when it comes out, which is why the type must beClone. - Option
- Lean’s
Option α. - Prod
- Lean’s
α × βas a pair. - String
- Lean’s
String. The Lean object holds a RustString, so a value moves both ways. - UInt8
- Lean’s
UInt8. - UInt16
- Lean’s
UInt16. - UInt32
- Lean’s
UInt32. - UInt64
- Lean’s
UInt64. - USize
- Lean’s
USize. - Unit
- Lean’s
Unit, where it is part of another type. - Value
- A Lean value of the type
Cstands for, with the one reference to it that the holder owns. Dropping it gives the reference up. - Via
- The Lean type of codec
Cas the Rust type the primitivePchose.
Traits§
- Codec
- A conversion between a Rust type and the Lean type the implementor stands for.
- Kept
ByLean ForAll Threads - A type whose values Lean may keep in a constant that every thread reads: one that is
Sync. - Pass
- An argument of type
Tfor a function written in Lean: the value itself, which moves into Lean, or a reference to it. A reference to a value that Lean converts, such as aString, is copied. A reference to a value that Lean holds as it is, of an opaque or a foreign type or a collection ofimport Inlean, is lent for the call: Lean reads the caller’s value, and clones it only where it needs one of its own. - Primitive
- A primitive type of your own: a Rust type of your choice in place of the one inlean gives a Lean type.
- Repr
- How Lean passes a value of a type: as an object, or as a scalar it keeps unboxed.
- Scalar
- A representation that is a plain number, with no reference to count.
- Word
- A Rust type that holds exactly the values of a
BitVec w: an unsigned integer ofwbits, orw / 64limbs with the least significant first.
Functions§
- given_
to_ a_ lean_ function - States that
Tis the type of a value that a trusted function gives to a Lean function it was passed. - returned_
by_ a_ trusted_ function - States that
Tis the type of a value that a trusted function returns to Lean.