Policy

Enum Policy 

Source
pub enum Policy<S: Scope> {
    Scope(S),
    OneOf(Vec<Policy<S>>),
    AllOf(Vec<Policy<S>>),
    Not(Box<Policy<S>>),
    AllowAll,
    DenyAll,
}
Expand description

A policy to verify a set of scopes

Policies can be combined using the &, | and ! operators :

let policy_a = MyScope::Foo.into_policy() & MyScope::Bar.into_policy();
 
let policy_b = (MyScope::Baz.into_policy() | MyScope::Bar.into_policy()) & !policy_a;

You can also use a PolicyBuilder<S> to build complex policies.

Variants§

§

Scope(S)

Requires a scope to be present

§

OneOf(Vec<Policy<S>>)

Requires one of the policies to be verified

§

AllOf(Vec<Policy<S>>)

Requires all of the policies to be verified

§

Not(Box<Policy<S>>)

Requires a policy not to be verified

§

AllowAll

Policy that always accept everything

§

DenyAll

Policy that accepts nothing

Implementations§

Source§

impl<S: Scope> Policy<S>

Source

pub fn builder() -> PolicyBuilder<S>

Create a new PolicyBuilder<S>

Equivalent to calling PolicyBuilder<S>::new

Source§

impl<S> Policy<S>
where S: Scope,

Source

pub fn verify<Iterator>(&self, scopes: Iterator) -> bool
where Iterator: IntoIterator + Clone, Iterator::Item: AsScopeRef<S>,

Check if a set of scopes is authorized by a policy

Trait Implementations§

Source§

impl<S, I> BitAnd<I> for Policy<S>
where S: Scope, I: IntoPolicy<S>,

Source§

type Output = Policy<S>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: I) -> Self::Output

Performs the & operation. Read more
Source§

impl<S, I> BitOr<I> for Policy<S>
where S: Scope, I: IntoPolicy<S>,

Source§

type Output = Policy<S>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: I) -> Self::Output

Performs the | operation. Read more
Source§

impl<S> Clone for Policy<S>
where S: Scope + Clone,

Source§

fn clone(&self) -> Self

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<S: Debug + Scope> Debug for Policy<S>

Source§

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

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

impl<S> Default for Policy<S>
where S: Scope,

Source§

fn default() -> Self

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

impl<S> From<&S> for Policy<S>
where S: Scope + Clone,

Source§

fn from(value: &S) -> Self

Converts to this type from the input type.
Source§

impl<S> From<S> for Policy<S>
where S: Scope,

Source§

fn from(value: S) -> Self

Converts to this type from the input type.
Source§

impl<S> Not for Policy<S>
where S: Scope,

Source§

type Output = Policy<S>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<S: PartialEq + Scope> PartialEq for Policy<S>

Source§

fn eq(&self, other: &Policy<S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S: Scope> StructuralPartialEq for Policy<S>

Auto Trait Implementations§

§

impl<S> Freeze for Policy<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Policy<S>
where S: RefUnwindSafe,

§

impl<S> Send for Policy<S>
where S: Send,

§

impl<S> Sync for Policy<S>
where S: Sync,

§

impl<S> Unpin for Policy<S>
where S: Unpin,

§

impl<S> UnwindSafe for Policy<S>
where S: UnwindSafe,

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, 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<S, I> IntoPolicy<S> for I
where S: Scope, I: Into<Policy<S>>,

Source§

fn into_policy(self) -> Policy<S>

Converts this type to a Policy<S>
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.