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,
impl<T> ExprBuilder<T>where
T: Default,
source§impl<T> ExprBuilder<T>
impl<T> ExprBuilder<T>
sourcepub fn with_data(data: T) -> Self
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.
sourcepub fn with_source_info(self, source_info: SourceInfo) -> Self
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.
sourcepub fn with_same_source_info<U>(self, expr: &Expr<U>) -> Self
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.
sourcepub fn val(self, v: impl Into<Literal>) -> Expr<T>
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.
sourcepub fn unknown(
self,
name: impl Into<SmolStr>,
type_annotation: Option<Type>,
) -> Expr<T>
pub fn unknown( self, name: impl Into<SmolStr>, type_annotation: Option<Type>, ) -> Expr<T>
Create an Unknown
Expr
sourcepub fn ite(
self,
test_expr: Expr<T>,
then_expr: Expr<T>,
else_expr: Expr<T>,
) -> Expr<T>
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
sourcepub fn not(self, e: Expr<T>) -> Expr<T>
pub fn not(self, e: Expr<T>) -> Expr<T>
Create a ‘not’ expression. e
must evaluate to Bool type
sourcepub fn and(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
pub fn and(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
Create an ‘and’ expression. Arguments must evaluate to Bool type
sourcepub fn or(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
pub fn or(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
Create an ‘or’ expression. Arguments must evaluate to Bool type
sourcepub fn less(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
pub fn less(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
Create a ‘<’ expression. Arguments must evaluate to Long type
sourcepub fn lesseq(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
pub fn lesseq(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
Create a ‘<=’ expression. Arguments must evaluate to Long type
sourcepub fn greater(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
pub fn greater(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
Create a ‘>’ expression. Arguments must evaluate to Long type
sourcepub fn greatereq(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
pub fn greatereq(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
Create a ‘>=’ expression. Arguments must evaluate to Long type
sourcepub fn add(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
pub fn add(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
Create an ‘add’ expression. Arguments must evaluate to Long type
sourcepub fn sub(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
pub fn sub(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
Create a ‘sub’ expression. Arguments must evaluate to Long type
sourcepub fn mul(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
pub fn mul(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
Create a ‘mul’ expression. Arguments must evaluate to Long type
sourcepub fn neg(self, e: Expr<T>) -> Expr<T>
pub fn neg(self, e: Expr<T>) -> Expr<T>
Create a ‘neg’ expression. e
must evaluate to Long type.
sourcepub fn is_in(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
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.
sourcepub fn contains(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
pub fn contains(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
Create a ‘contains’ expression. First argument must have Set type.
sourcepub fn contains_all(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
pub fn contains_all(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
Create a ‘contains_all’ expression. Arguments must evaluate to Set type
sourcepub fn contains_any(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
pub fn contains_any(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T>
Create an ‘contains_any’ expression. Arguments must evaluate to Set type
sourcepub fn set(self, exprs: impl IntoIterator<Item = Expr<T>>) -> Expr<T>
pub fn set(self, exprs: impl IntoIterator<Item = Expr<T>>) -> Expr<T>
Create an Expr
which evaluates to a Set of the given Expr
s
sourcepub fn record(
self,
pairs: impl IntoIterator<Item = (SmolStr, Expr<T>)>,
) -> Expr<T>
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.
sourcepub fn call_extension_fn(self, fn_name: Name, args: Vec<Expr<T>>) -> Expr<T>
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
sourcepub fn unary_app(self, op: impl Into<UnaryOp>, arg: Expr<T>) -> Expr<T>
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
sourcepub fn binary_app(
self,
op: impl Into<BinaryOp>,
arg1: Expr<T>,
arg2: Expr<T>,
) -> Expr<T>
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
sourcepub fn get_attr(self, expr: Expr<T>, attr: SmolStr) -> Expr<T>
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
sourcepub fn has_attr(self, expr: Expr<T>, attr: SmolStr) -> Expr<T>
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
sourcepub fn like(
self,
expr: Expr<T>,
pattern: impl IntoIterator<Item = PatternElem>,
) -> Expr<T>
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>
impl<T: Clone> ExprBuilder<T>
sourcepub fn and_nary(
self,
first: Expr<T>,
others: impl IntoIterator<Item = Expr<T>>,
) -> Expr<T>
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()
.
sourcepub fn or_nary(
self,
first: Expr<T>,
others: impl IntoIterator<Item = Expr<T>>,
) -> Expr<T>
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>
impl<T: Debug> Debug for ExprBuilder<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
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 more