Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 19 variants Nil, Bool(bool), Number(NumberLiteral), Symbol(Symbol), Local(Symbol), String(String), Bytes(Vec<u8>), List(Vec<Expr>), Vector(Vec<Expr>), Map(Vec<(Expr, Expr)>), Set(Vec<Expr>), Call { operator: Box<Expr>, args: Vec<Expr>, }, Infix { operator: Symbol, left: Box<Expr>, right: Box<Expr>, }, Prefix { operator: Symbol, arg: Box<Expr>, }, Postfix { operator: Symbol, arg: Box<Expr>, }, Block(Vec<Expr>), Quote { mode: QuoteMode, expr: Box<Expr>, }, Annotated { expr: Box<Expr>, annotations: Vec<(Symbol, Expr)>, }, Extension { tag: Symbol, payload: Box<Expr>, },
}
Expand description

The codec-neutral expression graph: the checked form of source.

The kernel defines this graph; general-purpose codecs in library crates round-trip every expression through it. It is the checked forms stage of the data flow tokens -> checked forms -> objects -> checked calls -> objects -> encoded forms. Equality and hashing are canonical (see Expr::canonical_eq): map entries and set members compare order-insensitively.

§Examples

let call = Expr::Call {
    operator: Box::new(Expr::Symbol(Symbol::new("add"))),
    args: vec![Expr::Bool(true), Expr::Nil],
};
// Maps compare canonically regardless of entry order.
let a = Expr::Set(vec![Expr::Bool(true), Expr::Nil]);
let b = Expr::Set(vec![Expr::Nil, Expr::Bool(true)]);
assert!(a.canonical_eq(&b));
let _ = call;

Variants§

§

Nil

The nil literal.

§

Bool(bool)

A boolean literal.

§

Number(NumberLiteral)

A number literal in some domain.

§

Symbol(Symbol)

A symbol reference.

§

Local(Symbol)

A lexical local reference.

§

String(String)

A string literal.

§

Bytes(Vec<u8>)

A byte-string literal.

§

List(Vec<Expr>)

An ordered list form.

§

Vector(Vec<Expr>)

An ordered vector form.

§

Map(Vec<(Expr, Expr)>)

A map form of key/value pairs (order-insensitive when compared).

§

Set(Vec<Expr>)

A set form (order-insensitive when compared).

§

Call

A call of operator with positional args.

Fields

§operator: Box<Expr>

The expression producing the callable operator.

§args: Vec<Expr>

The positional argument expressions.

§

Infix

An infix operator application.

Fields

§operator: Symbol

The operator symbol.

§left: Box<Expr>

The left operand.

§right: Box<Expr>

The right operand.

§

Prefix

A prefix operator application.

Fields

§operator: Symbol

The operator symbol.

§arg: Box<Expr>

The operand.

§

Postfix

A postfix operator application.

Fields

§operator: Symbol

The operator symbol.

§arg: Box<Expr>

The operand.

§

Block(Vec<Expr>)

A sequenced block of expressions.

§

Quote

A quoted expression carried at a given quote mode.

Fields

§mode: QuoteMode

The quote mode (quote, quasiquote, …).

§expr: Box<Expr>

The quoted expression.

§

Annotated

An expression carrying named annotations.

Fields

§expr: Box<Expr>

The annotated inner expression.

§annotations: Vec<(Symbol, Expr)>

The name/value annotation pairs.

§

Extension

An open extension form with a tag and payload.

Fields

§tag: Symbol

The extension tag.

§payload: Box<Expr>

The extension payload expression.

Implementations§

Source§

impl Expr

Source

pub fn canonical_key(&self) -> CanonicalKey

Computes the CanonicalKey backing canonical equality and hashing.

Source

pub fn canonical_eq(&self, other: &Self) -> bool

Returns whether two expressions are canonically equal.

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Expr

Source§

impl From<Datum> for Expr

Source§

fn from(datum: Datum) -> Self

Converts to this type from the input type.
Source§

impl From<Term> for Expr

Source§

fn from(term: Term) -> Self

Converts to this type from the input type.
Source§

impl Hash for Expr

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Expr

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<Expr> for Datum

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(expr: Expr) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Expr> for Term

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(expr: Expr) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnsafeUnpin for Expr

§

impl UnwindSafe for Expr

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.