Struct cedar_policy_core::evaluator::Evaluator
source · pub struct Evaluator<'e> { /* private fields */ }
Expand description
Evaluator object.
Conceptually keeps the evaluation environment as part of its internal state, because we will be repeatedly invoking the evaluator on every policy in a Slice.
Implementations§
source§impl<'q, 'e> Evaluator<'e>
impl<'q, 'e> Evaluator<'e>
sourcepub fn new(
q: &'q Request,
entities: &'e Entities,
extensions: &'e Extensions<'e>,
) -> Result<Self, EvaluationError>
pub fn new( q: &'q Request, entities: &'e Entities, extensions: &'e Extensions<'e>, ) -> Result<Self, EvaluationError>
Create a fresh Evaluator
for the given request
, which uses the given
Entities
to resolve entity references. Use the given Extension
s when
evaluating the request.
(An Entities
is the entity-hierarchy portion of a Slice
, without the
policies.)
Can throw an error, eg if evaluating attributes in the context
throws
an error.
sourcepub fn evaluate(&self, p: &Policy) -> Result<bool, EvaluationError>
pub fn evaluate(&self, p: &Policy) -> Result<bool, EvaluationError>
Evaluate the given Policy
, returning either a bool or an error.
The bool indicates whether the policy applies, ie, “is satisfied” for the
current request
.
This is different than “if the current request
should be allowed” –
it doesn’t consider whether we’re processing a Permit
policy or a
Forbid
policy.
sourcepub fn partial_evaluate(
&self,
p: &Policy,
) -> Result<Either<bool, Expr>, EvaluationError>
pub fn partial_evaluate( &self, p: &Policy, ) -> Result<Either<bool, Expr>, EvaluationError>
Partially evaluate the given Policy
, returning one of:
- A boolean, if complete evaluation was possible
- An error, if the policy is guaranteed to error
- A residual, if complete evaluation was impossible
The bool indicates whether the policy applies, ie, “is satisfied” for the
current
request
. This is different than “if the currentrequest
should be allowed” – it doesn’t consider whether we’re processing aPermit
policy or aForbid
policy.
sourcepub fn run_to_error(
&self,
e: &Expr,
slots: &SlotEnv,
) -> (PartialValue, Option<EvaluationError>)
pub fn run_to_error( &self, e: &Expr, slots: &SlotEnv, ) -> (PartialValue, Option<EvaluationError>)
Run an expression as far as possible.
however, if an error is encountered, instead of error-ing, wrap the error
in a call the error
extension function.
sourcepub fn interpret(
&self,
e: &Expr,
slots: &SlotEnv,
) -> Result<Value, EvaluationError>
pub fn interpret( &self, e: &Expr, slots: &SlotEnv, ) -> Result<Value, EvaluationError>
Interpret an Expr
into a Value
in this evaluation environment.
Ensures the result is not a residual.
May return an error, for instance if the Expr
tries to access an
attribute that doesn’t exist.
sourcepub fn partial_interpret(
&self,
e: &Expr,
slots: &SlotEnv,
) -> Result<PartialValue, EvaluationError>
pub fn partial_interpret( &self, e: &Expr, slots: &SlotEnv, ) -> Result<PartialValue, EvaluationError>
Interpret an Expr
into a Value
in this evaluation environment.
May return a residual expression, if the input expression is symbolic.
May return an error, for instance if the Expr
tries to access an
attribute that doesn’t exist.
Trait Implementations§
Auto Trait Implementations§
impl<'e> Freeze for Evaluator<'e>
impl<'e> !RefUnwindSafe for Evaluator<'e>
impl<'e> !Send for Evaluator<'e>
impl<'e> !Sync for Evaluator<'e>
impl<'e> Unpin for Evaluator<'e>
impl<'e> !UnwindSafe for Evaluator<'e>
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