Struct cedar_policy_core::ast::ExprBuilder

source ·
pub struct ExprBuilder<T> { /* private fields */ }
Expand description

Builder for constructing Expr objects annotated with some data (possibly taking default value) and optional some source_info.

Implementations§

source§

impl<T> ExprBuilder<T>
where T: Default,

source

pub fn new() -> Self

Construct a new ExprBuilder where the data used for an expression takes a default value.

source

pub fn noteq(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘!=’ expression. Defined only for T: Default because the caller would otherwise need to provide a data for the intermediate not Expr node.

source§

impl<T> ExprBuilder<T>

source

pub fn with_data(data: T) -> Self

Construct a new ExprBuild where the specified data will be stored on the Expr. This constructor does not populate the source_info field, so with_source_info should be called if constructing an Expr where the source location is known.

source

pub fn with_source_info(self, source_info: SourceInfo) -> Self

Update the ExprBuilder to build an expression with some known location in policy source code.

source

pub fn with_same_source_info<U>(self, expr: &Expr<U>) -> Self

Utility used the validator to get an expression with the same source location as an existing expression. This is done when reconstructing the Expr with type information.

source

pub fn val(self, v: impl Into<Literal>) -> Expr<T>

Create an Expr that’s just a single Literal.

Note that you can pass this a Literal, an i64, a String, etc.

source

pub fn unknown( self, name: impl Into<SmolStr>, type_annotation: Option<Type>, ) -> Expr<T>

Create an Unknown Expr

source

pub fn var(self, v: Var) -> Expr<T>

Create an Expr that’s just this literal Var

source

pub fn slot(self, s: SlotId) -> Expr<T>

Create an Expr that’s just this SlotId

source

pub fn ite( self, test_expr: Expr<T>, then_expr: Expr<T>, else_expr: Expr<T>, ) -> Expr<T>

Create a ternary (if-then-else) Expr.

test_expr must evaluate to a Bool type

source

pub fn not(self, e: Expr<T>) -> Expr<T>

Create a ‘not’ expression. e must evaluate to Bool type

source

pub fn is_eq(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘==’ expression

source

pub fn and(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create an ‘and’ expression. Arguments must evaluate to Bool type

source

pub fn or(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create an ‘or’ expression. Arguments must evaluate to Bool type

source

pub fn less(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘<’ expression. Arguments must evaluate to Long type

source

pub fn lesseq(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘<=’ expression. Arguments must evaluate to Long type

source

pub fn greater(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘>’ expression. Arguments must evaluate to Long type

source

pub fn greatereq(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘>=’ expression. Arguments must evaluate to Long type

source

pub fn add(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create an ‘add’ expression. Arguments must evaluate to Long type

source

pub fn sub(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘sub’ expression. Arguments must evaluate to Long type

source

pub fn mul(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘mul’ expression. Arguments must evaluate to Long type

source

pub fn neg(self, e: Expr<T>) -> Expr<T>

Create a ‘neg’ expression. e must evaluate to Long type.

source

pub fn is_in(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create an ‘in’ expression. First argument must evaluate to Entity type. Second argument must evaluate to either Entity type or Set type where all set elements have Entity type.

source

pub fn contains(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘contains’ expression. First argument must have Set type.

source

pub fn contains_all(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create a ‘contains_all’ expression. Arguments must evaluate to Set type

source

pub fn contains_any(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>

Create an ‘contains_any’ expression. Arguments must evaluate to Set type

source

pub fn set(self, exprs: impl IntoIterator<Item = Expr<T>>) -> Expr<T>

Create an Expr which evaluates to a Set of the given Exprs

source

pub fn record( self, pairs: impl IntoIterator<Item = (SmolStr, Expr<T>)>, ) -> Expr<T>

Create an Expr which evaluates to a Record with the given (key, value) pairs.

source

pub fn call_extension_fn(self, fn_name: Name, args: Vec<Expr<T>>) -> Expr<T>

Create an Expr which calls the extension function with the given Name on args

source

pub fn unary_app(self, op: impl Into<UnaryOp>, arg: Expr<T>) -> Expr<T>

Create an application Expr which applies the given built-in unary operator to the given arg

source

pub fn binary_app( self, op: impl Into<BinaryOp>, arg1: Expr<T>, arg2: Expr<T>, ) -> Expr<T>

Create an application Expr which applies the given built-in binary operator to arg1 and arg2

source

pub fn get_attr(self, expr: Expr<T>, attr: SmolStr) -> Expr<T>

Create an Expr which gets the attribute of some Entity or the field of some record.

expr must evaluate to either Entity or Record type

source

pub fn has_attr(self, expr: Expr<T>, attr: SmolStr) -> Expr<T>

Create an Expr which tests for the existence of a given attribute on a given Entity, or field on a given record.

expr must evaluate to either Entity or Record type

source

pub fn like( self, expr: Expr<T>, pattern: impl IntoIterator<Item = PatternElem>, ) -> Expr<T>

Create a ‘like’ expression.

expr must evaluate to a String type

source§

impl<T: Clone> ExprBuilder<T>

source

pub fn and_nary( self, first: Expr<T>, others: impl IntoIterator<Item = Expr<T>>, ) -> Expr<T>

Create an and expression that may have more than two subexpressions (A && B && C) or may have only one subexpression, in which case no && is performed at all. Arguments must evaluate to Bool type.

This may create multiple AST && nodes. If it does, all the nodes will have the same source location and the same T data (taken from this builder) unless overridden, e.g., with another call to with_source_info().

source

pub fn or_nary( self, first: Expr<T>, others: impl IntoIterator<Item = Expr<T>>, ) -> Expr<T>

Create an or expression that may have more than two subexpressions (A || B || C) or may have only one subexpression, in which case no || is performed at all. Arguments must evaluate to Bool type.

This may create multiple AST || nodes. If it does, all the nodes will have the same source location and the same T data (taken from this builder) unless overridden, e.g., with another call to with_source_info().

Trait Implementations§

source§

impl<T: Debug> Debug for ExprBuilder<T>

source§

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

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

impl<T: Default> Default for ExprBuilder<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for ExprBuilder<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ExprBuilder<T>
where T: RefUnwindSafe,

§

impl<T> Send for ExprBuilder<T>
where T: Send,

§

impl<T> Sync for ExprBuilder<T>
where T: Sync,

§

impl<T> Unpin for ExprBuilder<T>
where T: Unpin,

§

impl<T> UnwindSafe for ExprBuilder<T>
where T: UnwindSafe,

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> 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> 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, 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.