Expression

Struct Expression 

Source
pub struct Expression { /* private fields */ }
Expand description

An expression in a Gordian Envelope.

An expression consists of a function (the subject of the envelope) and zero or more parameters (as assertions on the envelope). It represents a computation or function call that can be evaluated.

Expressions form the foundation for Gordian Envelope’s ability to represent computations, queries, and function calls within the envelope structure.

Expressions are documented in BCR-2023-012: Envelope Expressions.

§Examples

A simple addition expression:

use bc_envelope::prelude::*;

// Create an expression that adds 2 and 3
let expression = Expression::new(functions::ADD)
    .with_parameter(parameters::LHS, 2)
    .with_parameter(parameters::RHS, 3);

A more complex expression:

use bc_envelope::prelude::*;

// Create a verify signature expression with a public key, signature, and digest
let expression = Expression::new("verifySignature")
    .with_parameter("key", public_key)
    .with_parameter("sig", signature)
    .with_parameter("digest", message_digest);

Implementations§

Source§

impl Expression

Source

pub fn new(function: impl Into<Function>) -> Self

Creates a new expression with the given function.

The function becomes the subject of the expression envelope.

§Parameters
  • function - The function identifier for this expression
§Returns

A new Expression instance

§Examples
use bc_envelope::prelude::*;

// Create a new expression with the ADD function
let expression = Expression::new(functions::ADD);

// Create a new expression with a named function
let expression = Expression::new("verifySignature");

Trait Implementations§

Source§

impl Clone for Expression

Source§

fn clone(&self) -> Expression

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Expression

Source§

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

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

impl Display for Expression

Implements Display for Expression.

Outputs the formatted envelope representation of the expression.

Source§

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

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

impl ExpressionBehavior for Expression

Implementation of ExpressionBehavior for Expression.

Source§

fn with_parameter( self, parameter: impl Into<Parameter>, value: impl EnvelopeEncodable, ) -> Self

Adds a parameter to the expression.

Source§

fn with_optional_parameter( self, parameter: impl Into<Parameter>, value: Option<impl EnvelopeEncodable>, ) -> Self

Adds a parameter to the expression if the value is not None.

Source§

fn function(&self) -> &Function

Returns the function of the expression.

Source§

fn expression_envelope(&self) -> &Envelope

Returns the envelope representing the expression.

Source§

fn object_for_parameter(&self, param: impl Into<Parameter>) -> Result<Envelope>

Returns the argument for the given parameter.

Source§

fn objects_for_parameter(&self, param: impl Into<Parameter>) -> Vec<Envelope>

Returns all arguments for the given parameter.

Source§

fn extract_object_for_parameter<T>( &self, param: impl Into<Parameter>, ) -> Result<T>
where T: TryFrom<CBOR, Error = Error> + 'static,

Returns the argument for the given parameter, decoded as the given type.

Source§

fn extract_optional_object_for_parameter<T: TryFrom<CBOR, Error = Error> + 'static>( &self, param: impl Into<Parameter>, ) -> Result<Option<T>>

Returns the argument for the given parameter, decoded as the given type, or None if there is no matching parameter.

Source§

fn extract_objects_for_parameter<T>( &self, param: impl Into<Parameter>, ) -> Result<Vec<T>>
where T: TryFrom<CBOR, Error = Error> + 'static,

Returns an array of arguments for the given parameter, decoded as the given type.

Source§

impl From<Expression> for Envelope

Allows converting an Expression to an Envelope.

This simply returns the envelope that represents the expression.

Source§

fn from(expression: Expression) -> Self

Converts to this type from the input type.
Source§

impl From<Request> for Expression

Converts a Request to an Expression.

This extracts the request’s body expression.

Source§

fn from(request: Request) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Expression

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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<(Envelope, Option<&Function>)> for Expression

Allows converting an Envelope and optional expected function to an Expression.

This is similar to TryFrom<Envelope>, but it also checks that the function matches the expected function, if provided.

§Errors

Returns an error if:

  • The envelope’s subject cannot be extracted as a Function
  • The expected function is provided and doesn’t match the extracted function
Source§

type Error = Error

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

fn try_from( (envelope, expected_function): (Envelope, Option<&Function>), ) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Envelope> for Expression

Allows converting an Envelope to an Expression.

This extracts the function from the envelope’s subject and creates an Expression with that function and the envelope.

§Errors

Returns an error if the envelope’s subject cannot be extracted as a Function.

Source§

type Error = Error

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

fn try_from(envelope: Envelope) -> Result<Self>

Performs the conversion.
Source§

impl StructuralPartialEq for Expression

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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> EnvelopeEncodable for T
where T: Into<Envelope> + Clone,

Source§

fn into_envelope(self) -> Envelope

Converts the value into an envelope by using its Into<Envelope> implementation.

Source§

fn to_envelope(&self) -> Envelope
where Self: Clone,

Converts a reference to this value into a Gordian Envelope. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoExpression for T
where T: Into<Expression> + Clone,

Source§

fn into_expression(self) -> Expression

Converts this object into an Expression, consuming it.

Source§

fn to_expression(&self) -> Expression

Creates an Expression from this object, without consuming it.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V