pub struct Scope { /* private fields */ }
Expand description

Scope of a given grant or resource, a set of scope-tokens separated by spaces.

Scopes are interpreted as a conjunction of scope tokens, i.e. a scope is fulfilled if all of its scope tokens are fulfilled. This induces a partial ordering on scopes where scope A is less or equal than scope B if all scope tokens of A are also found in B. This can be interpreted as the rule

A token with scope B is allowed to access a resource requiring scope A iff A <= B

Example

let grant_scope    = "some_scope other_scope".parse::<Scope>().unwrap();
let resource_scope = "some_scope".parse::<Scope>().unwrap();
let uncomparable   = "some_scope third_scope".parse::<Scope>().unwrap();

// Holding a grant with `grant_scope` allows access to the resource since:
assert!(resource_scope <= grant_scope);
assert!(resource_scope.allow_access(&grant_scope));

// But holders would not be allowed to access another resource with scope `uncomparable`:
assert!(!(uncomparable <= grant_scope));
assert!(!uncomparable.allow_access(&grant_scope));

// This would also not work the other way around:
assert!(!(grant_scope <= uncomparable));
assert!(!grant_scope.allow_access(&uncomparable));

Scope-tokens are restricted to the following subset of ascii:

  • The character ‘!’
  • The character range ‘\x32’ to ‘\x5b’ which includes numbers and upper case letters
  • The character range ‘\x5d’ to ‘\x7e’ which includes lower case letters Individual scope-tokens are separated by spaces.

In particular, the characters ‘\x22’ (") and ‘\x5c’ (\) are not allowed.

Implementations§

source§

impl Scope

source

pub fn priviledged_to(&self, rhs: &Scope) -> bool

Determines if this scope has enough privileges to access some resource requiring the scope on the right side. This operation is equivalent to comparison via >=.

source

pub fn allow_access(&self, rhs: &Scope) -> bool

Determines if a resouce protected by this scope should allow access to a token with the grant on the right side. This operation is equivalent to comparison via <=.

source

pub fn iter(&self) -> impl Iterator<Item = &str>

Create an iterator over the individual scopes.

Trait Implementations§

source§

impl Clone for Scope

source§

fn clone(&self) -> Scope

Returns a copy 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 Scope

source§

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

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

impl<'de> Deserialize<'de> for Scope

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Scope

source§

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

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

impl FromStr for Scope

§

type Err = ParseScopeErr

The associated error which can be returned from parsing.
source§

fn from_str(string: &str) -> Result<Scope, ParseScopeErr>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq<Scope> for Scope

source§

fn eq(&self, other: &Scope) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Scope> for Scope

source§

fn partial_cmp(&self, rhs: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Scope

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Scope

source§

impl StructuralEq for Scope

source§

impl StructuralPartialEq for Scope

Auto Trait Implementations§

§

impl RefUnwindSafe for Scope

§

impl Send for Scope

§

impl Sync for Scope

§

impl Unpin for Scope

§

impl UnwindSafe for Scope

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,