pub struct ExprBuilder<T> { /* private fields */ }Expand description
Builder for constructing Expr objects annotated with some data
(possibly taking default value) and optionally a source_loc.
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_loc field,
so with_source_loc should be called if constructing an Expr where
the source location is known.
Sourcepub fn with_source_loc(self, source_loc: Loc) -> Self
pub fn with_source_loc(self, source_loc: Loc) -> Self
Update the ExprBuilder to build an expression with some known location
in policy source code.
Sourcepub fn with_same_source_loc<U>(self, expr: &Expr<U>) -> Self
pub fn with_same_source_loc<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 Integer, a String, etc.
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 ite_arc(
self,
test_expr: Arc<Expr<T>>,
then_expr: Arc<Expr<T>>,
else_expr: Arc<Expr<T>>,
) -> Expr<T>
pub fn ite_arc( self, test_expr: Arc<Expr<T>>, then_expr: Arc<Expr<T>>, else_expr: Arc<Expr<T>>, ) -> Expr<T>
Create a ternary (if-then-else) Expr.
Takes Arcs instead of owned Exprs.
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 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 Exprs
Sourcepub fn record(
self,
pairs: impl IntoIterator<Item = (SmolStr, Expr<T>)>,
) -> Result<Expr<T>, ExpressionConstructionError>
pub fn record( self, pairs: impl IntoIterator<Item = (SmolStr, Expr<T>)>, ) -> Result<Expr<T>, ExpressionConstructionError>
Create an Expr which evaluates to a Record with the given (key, value) pairs.
Sourcepub fn record_arc(self, map: Arc<BTreeMap<SmolStr, Expr<T>>>) -> Expr<T>
pub fn record_arc(self, map: Arc<BTreeMap<SmolStr, Expr<T>>>) -> Expr<T>
Create an Expr which evalutes to a Record with the given key-value mapping.
If you have an iterator of pairs, generally prefer calling .record()
instead of .collect()-ing yourself and calling this, potentially for
efficiency reasons but also because .record() will properly handle
duplicate keys but your own .collect() will not (by default).
Sourcepub fn call_extension_fn(
self,
fn_name: Name,
args: impl IntoIterator<Item = Expr<T>>,
) -> Expr<T>
pub fn call_extension_fn( self, fn_name: Name, args: impl IntoIterator<Item = 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
Sourcepub fn is_entity_type(self, expr: Expr<T>, entity_type: EntityType) -> Expr<T>
pub fn is_entity_type(self, expr: Expr<T>, entity_type: EntityType) -> Expr<T>
Create an ‘is’ expression.
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_loc().
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_loc().
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