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
impl Expression
Sourcepub fn new(function: impl Into<Function>) -> Self
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
impl Clone for Expression
Source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Expression
impl Debug for Expression
Source§impl Display for Expression
Implements Display for Expression.
impl Display for Expression
Implements Display for Expression.
Outputs the formatted envelope representation of the expression.
Source§impl ExpressionBehavior for Expression
Implementation of ExpressionBehavior for Expression.
impl ExpressionBehavior for Expression
Implementation of ExpressionBehavior for Expression.
Source§fn with_parameter(
self,
parameter: impl Into<Parameter>,
value: impl EnvelopeEncodable,
) -> Self
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
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 expression_envelope(&self) -> &Envelope
fn expression_envelope(&self) -> &Envelope
Returns the envelope representing the expression.
Source§fn object_for_parameter(&self, param: impl Into<Parameter>) -> Result<Envelope>
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>
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>
fn extract_object_for_parameter<T>( &self, param: impl Into<Parameter>, ) -> Result<T>
Returns the argument for the given parameter, decoded as the given type.
Source§impl From<Expression> for Envelope
Allows converting an Expression to an Envelope.
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
fn from(expression: Expression) -> Self
Source§impl From<Request> for Expression
Converts a Request to an Expression.
impl From<Request> for Expression
Converts a Request to an Expression.
This extracts the request’s body expression.
Source§impl PartialEq for Expression
impl PartialEq for Expression
Source§impl TryFrom<(Envelope, Option<&Function>)> for Expression
Allows converting an Envelope and optional expected function to an
Expression.
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§impl TryFrom<Envelope> for Expression
Allows converting an Envelope to an Expression.
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.
impl StructuralPartialEq for Expression
Auto Trait Implementations§
impl Freeze for Expression
impl RefUnwindSafe for Expression
impl !Send for Expression
impl !Sync for Expression
impl Unpin for Expression
impl UnwindSafe for Expression
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<T> EnvelopeEncodable for T
impl<T> EnvelopeEncodable for T
Source§fn into_envelope(self) -> Envelope
fn into_envelope(self) -> Envelope
Converts the value into an envelope by using its Into<Envelope>
implementation.
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoExpression for T
impl<T> IntoExpression for T
Source§fn into_expression(self) -> Expression
fn into_expression(self) -> Expression
Converts this object into an Expression, consuming it.
Source§fn to_expression(&self) -> Expression
fn to_expression(&self) -> Expression
Creates an Expression from this object, without consuming it.