Struct cedar_policy_core::ast::BorrowedRestrictedExpr
source · pub struct BorrowedRestrictedExpr<'a>(/* private fields */);
Expand description
While RestrictedExpr
wraps an owned Expr
, BorrowedRestrictedExpr
wraps a borrowed Expr
, with the same invariants.
Implementations§
source§impl<'a> BorrowedRestrictedExpr<'a>
impl<'a> BorrowedRestrictedExpr<'a>
sourcepub fn new(expr: &'a Expr) -> Result<Self, RestrictedExpressionError>
pub fn new(expr: &'a Expr) -> Result<Self, RestrictedExpressionError>
Create a new BorrowedRestrictedExpr
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: &'a Expr) -> Self
pub fn new_unchecked(expr: &'a Expr) -> Self
Create a new BorrowedRestrictedExpr
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 to_natural_json(self) -> Result<Value, JsonSerializationError>
pub fn to_natural_json(self) -> Result<Value, JsonSerializationError>
Write a BorrowedRestrictedExpr in “natural JSON” format.
Used to output the context as a map from Strings to JSON Values
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<'a> AsRef<Expr> for BorrowedRestrictedExpr<'a>
impl<'a> AsRef<Expr> for BorrowedRestrictedExpr<'a>
source§impl<'a> Clone for BorrowedRestrictedExpr<'a>
impl<'a> Clone for BorrowedRestrictedExpr<'a>
source§fn clone(&self) -> BorrowedRestrictedExpr<'a>
fn clone(&self) -> BorrowedRestrictedExpr<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for BorrowedRestrictedExpr<'a>
impl<'a> Debug for BorrowedRestrictedExpr<'a>
source§impl<'a> Display for BorrowedRestrictedExpr<'a>
impl<'a> Display for BorrowedRestrictedExpr<'a>
source§impl<'a> From<BorrowedRestrictedExpr<'a>> for &'a Expr
impl<'a> From<BorrowedRestrictedExpr<'a>> for &'a Expr
source§fn from(r: BorrowedRestrictedExpr<'a>) -> &'a Expr
fn from(r: BorrowedRestrictedExpr<'a>) -> &'a Expr
source§impl<'a> Hash for BorrowedRestrictedExpr<'a>
impl<'a> Hash for BorrowedRestrictedExpr<'a>
source§impl<'a> PartialEq for BorrowedRestrictedExpr<'a>
impl<'a> PartialEq for BorrowedRestrictedExpr<'a>
source§impl<'a> Serialize for BorrowedRestrictedExpr<'a>
impl<'a> Serialize for BorrowedRestrictedExpr<'a>
source§impl<'a> Deref for BorrowedRestrictedExpr<'a>
impl<'a> Deref for BorrowedRestrictedExpr<'a>
impl<'a> Eq for BorrowedRestrictedExpr<'a>
impl<'a> StructuralPartialEq for BorrowedRestrictedExpr<'a>
Auto Trait Implementations§
impl<'a> Freeze for BorrowedRestrictedExpr<'a>
impl<'a> RefUnwindSafe for BorrowedRestrictedExpr<'a>
impl<'a> Send for BorrowedRestrictedExpr<'a>
impl<'a> Sync for BorrowedRestrictedExpr<'a>
impl<'a> Unpin for BorrowedRestrictedExpr<'a>
impl<'a> UnwindSafe for BorrowedRestrictedExpr<'a>
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