Struct EvalTrace

Source
pub struct EvalTrace { /* private fields */ }
Expand description

Container for the evaluation tree Detailed trace of all policy evaluations

Implementations§

Source§

impl EvalTrace

Source

pub fn new() -> Self

Source

pub fn with_root(result: PolicyEvalResult) -> Self

Source

pub fn set_root(&mut self, result: PolicyEvalResult)

Source

pub fn root(&self) -> Option<&PolicyEvalResult>

Source

pub fn format(&self) -> String

Returns a formatted representation of the evaluation tree

Examples found in repository?
examples/rbac_policy.rs (line 212)
186async fn test_access(
187    checker: &PermissionChecker<User, Document, ReadAction, EmptyContext>,
188    user_desc: &str,
189    user: &User,
190    doc_desc: &str,
191    doc: &Document,
192) {
193    let context = EmptyContext;
194    let action = ReadAction;
195
196    let result = checker.evaluate_access(user, &action, doc, &context).await;
197
198    println!(
199        "{} accessing {}: {}",
200        user_desc,
201        doc_desc,
202        if result.is_granted() {
203            "GRANTED ✓"
204        } else {
205            "DENIED ✗"
206        }
207    );
208
209    println!(
210        "Evaluation trace:\n{}\n",
211        match &result {
212            AccessEvaluation::Granted { trace, .. } => trace.format(),
213            AccessEvaluation::Denied { trace, .. } => trace.format(),
214        }
215    );
216}
More examples
Hide additional examples
examples/rebac_policy.rs (line 238)
212async fn test_access(
213    checker: &PermissionChecker<User, Project, EditAction, EmptyContext>,
214    user: &User,
215    project: &Project,
216) {
217    let context = EmptyContext;
218    let action = EditAction;
219
220    println!("\nChecking if {} can edit {}:", user.name, project.name);
221    let result = checker
222        .evaluate_access(user, &action, project, &context)
223        .await;
224
225    println!(
226        "Access {} for {}",
227        if result.is_granted() {
228            "GRANTED ✓"
229        } else {
230            "DENIED ✗"
231        },
232        user.name
233    );
234
235    println!(
236        "Evaluation trace:\n{}\n",
237        match &result {
238            AccessEvaluation::Granted { trace, .. } => trace.format(),
239            AccessEvaluation::Denied { trace, .. } => trace.format(),
240        }
241    );
242}

Trait Implementations§

Source§

impl Clone for EvalTrace

Source§

fn clone(&self) -> EvalTrace

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EvalTrace

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for EvalTrace

Source§

fn default() -> EvalTrace

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more