Struct cedar_policy_core::ast::RestrictedExpr
source · pub struct RestrictedExpr(/* private fields */);
Expand description
A few places in Core use these “restricted expressions” (for lack of a
better term) which are in some sense the minimal subset of Expr
required
to express all possible Value
s.
Specifically, “restricted” expressions are defined as expressions containing only the following:
- bool, int, and string literals
- literal EntityUIDs such as User::“alice”
- extension function calls, where the arguments must be other things on this list
- set and record literals, where the values must be other things on this list
That means the following are not allowed in “restricted” expressions:
principal
,action
,resource
,context
- builtin operators and functions, including
.
,in
,has
,like
,.contains()
- if-then-else expressions
These restrictions represent the expressions that are allowed to appear as
attribute values in Slice
and Context
.
Implementations§
source§impl RestrictedExpr
impl RestrictedExpr
sourcepub fn new(expr: Expr) -> Result<Self, RestrictedExpressionError>
pub fn new(expr: Expr) -> Result<Self, RestrictedExpressionError>
Create a new RestrictedExpr
from an Expr
.
This function is “safe” in the sense that it will verify that the
provided expr
does indeed qualify as a “restricted” expression,
returning an error if not.
Note this check requires recursively walking the AST. For a version of
this function that doesn’t perform this check, see new_unchecked()
below.
sourcepub fn new_unchecked(expr: Expr) -> Self
pub fn new_unchecked(expr: Expr) -> Self
Create a new RestrictedExpr
from an Expr
, where the caller is
responsible for ensuring that the Expr
is a valid “restricted
expression”. If it is not, internal invariants will be violated, which
may lead to other errors later, panics, or even incorrect results.
For a “safer” version of this function that returns an error for invalid
inputs, see new()
above.
sourcepub fn val(v: impl Into<Literal>) -> Self
pub fn val(v: impl Into<Literal>) -> Self
Create a RestrictedExpr
that’s just a single Literal
.
Note that you can pass this a Literal
, an i64
, a String
, etc.
sourcepub fn set(exprs: impl IntoIterator<Item = RestrictedExpr>) -> Self
pub fn set(exprs: impl IntoIterator<Item = RestrictedExpr>) -> Self
Create a RestrictedExpr
which evaluates to a Set of the given RestrictedExpr
s
sourcepub fn record(
pairs: impl IntoIterator<Item = (SmolStr, RestrictedExpr)>,
) -> Self
pub fn record( pairs: impl IntoIterator<Item = (SmolStr, RestrictedExpr)>, ) -> Self
Create a RestrictedExpr
which evaluates to a Record with the given (key, value) pairs.
sourcepub fn call_extension_fn(function_name: Name, args: Vec<RestrictedExpr>) -> Self
pub fn call_extension_fn(function_name: Name, args: Vec<RestrictedExpr>) -> Self
Create a RestrictedExpr
which calls the given extension function
source§impl RestrictedExpr
impl RestrictedExpr
sourcepub fn as_borrowed(&self) -> BorrowedRestrictedExpr<'_>
pub fn as_borrowed(&self) -> BorrowedRestrictedExpr<'_>
Turn an &RestrictedExpr
into a BorrowedRestrictedExpr
Methods from Deref<Target = Expr>§
sourcepub fn expr_kind(&self) -> &ExprKind<T>
pub fn expr_kind(&self) -> &ExprKind<T>
Access the inner ExprKind
for this Expr
. The ExprKind
is the
enum
which specifies the expression variant, so it must be accessed by
any code matching and recursing on an expression.
sourcepub fn source_info(&self) -> &Option<SourceInfo>
pub fn source_info(&self) -> &Option<SourceInfo>
Access the data stored on the Expr
.
sourcepub fn is_ref(&self) -> bool
pub fn is_ref(&self) -> bool
Check whether this expression is an entity reference
This is used for policy headers, where some syntax is required to be an entity reference.
sourcepub fn is_ref_set(&self) -> bool
pub fn is_ref_set(&self) -> bool
Check whether this expression is a set of entity references
This is used for policy headers, where some syntax is required to be an entity reference set.
sourcepub fn subexpressions(&self) -> impl Iterator<Item = &Self>
pub fn subexpressions(&self) -> impl Iterator<Item = &Self>
Iterate over all sub-expressions in this expression
sourcepub fn slots(&self) -> impl Iterator<Item = &SlotId>
pub fn slots(&self) -> impl Iterator<Item = &SlotId>
Iterate over all of the slots in this policy AST
sourcepub fn is_projectable(&self) -> bool
pub fn is_projectable(&self) -> bool
Determine if the expression is projectable under partial evaluation An expression is projectable if it’s guaranteed to never error on evaluation This is true if the expression is entirely composed of values or unknowns
sourcepub fn is_unknown(&self) -> bool
pub fn is_unknown(&self) -> bool
Check if an expression contains any symbolic unknowns
sourcepub fn substitute(
&self,
definitions: &HashMap<SmolStr, Value>,
) -> Result<Expr, SubstitutionError>
pub fn substitute( &self, definitions: &HashMap<SmolStr, Value>, ) -> Result<Expr, SubstitutionError>
Substitute unknowns with values If a definition is missing, it will be left as an unknown, and can be filled in later.
sourcepub fn eq_shape<U>(&self, other: &Expr<U>) -> bool
pub fn eq_shape<U>(&self, other: &Expr<U>) -> bool
Return true if this expression (recursively) has the same expression
kind as the argument expression. This accounts for the full recursive
shape of the expression, but does not consider source information or any
generic data annotated on expression. This should behave the same as the
default implementation of Eq
before source information and generic
data were added.
sourcepub fn hash_shape<H>(&self, state: &mut H)where
H: Hasher,
pub fn hash_shape<H>(&self, state: &mut H)where
H: Hasher,
Implementation of hashing corresponding to equality as implemented by
eq_shape
. Must satisfy the usual relationship between equality and
hashing.
Trait Implementations§
source§impl AsRef<Expr> for RestrictedExpr
impl AsRef<Expr> for RestrictedExpr
source§impl AsRef<RestrictedExpr> for Context
impl AsRef<RestrictedExpr> for Context
source§fn as_ref(&self) -> &RestrictedExpr
fn as_ref(&self) -> &RestrictedExpr
source§impl Clone for RestrictedExpr
impl Clone for RestrictedExpr
source§fn clone(&self) -> RestrictedExpr
fn clone(&self) -> RestrictedExpr
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for RestrictedExpr
impl Debug for RestrictedExpr
source§impl<'de> Deserialize<'de> for RestrictedExpr
impl<'de> Deserialize<'de> for RestrictedExpr
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for RestrictedExpr
impl Display for RestrictedExpr
source§impl From<RestrictedExpr> for Expr
impl From<RestrictedExpr> for Expr
source§fn from(r: RestrictedExpr) -> Expr
fn from(r: RestrictedExpr) -> Expr
source§impl FromStr for RestrictedExpr
impl FromStr for RestrictedExpr
source§impl Hash for RestrictedExpr
impl Hash for RestrictedExpr
source§impl PartialEq for RestrictedExpr
impl PartialEq for RestrictedExpr
source§impl Serialize for RestrictedExpr
impl Serialize for RestrictedExpr
source§impl Deref for RestrictedExpr
impl Deref for RestrictedExpr
impl Eq for RestrictedExpr
impl StructuralPartialEq for RestrictedExpr
Auto Trait Implementations§
impl Freeze for RestrictedExpr
impl RefUnwindSafe for RestrictedExpr
impl Send for RestrictedExpr
impl Sync for RestrictedExpr
impl Unpin for RestrictedExpr
impl UnwindSafe for RestrictedExpr
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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