cedar_policy_core::evaluator

Struct 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<'e> Evaluator<'e>

Source

pub fn new( q: Request, entities: &'e Entities, extensions: &'e Extensions<'e>, ) -> Self

Create a fresh Evaluator for the given request, which uses the given Entities to resolve entity references. Use the given Extensions when evaluating.

Source

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.

Source

pub fn partial_evaluate( &self, p: &Policy, ) -> Result<Either<bool, Expr>, EvaluationError>

Partially evaluate the given Policy, returning one of:

  1. A boolean, if complete evaluation was possible
  2. An error, if the policy is guaranteed to error
  3. 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 current request should be allowed” – it doesn’t consider whether we’re processing a Permit policy or a Forbid policy.
Source

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.

Source

pub fn partial_interpret( &self, expr: &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§

Source§

impl<'e> Debug for Evaluator<'e>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.