#[non_exhaustive]pub enum Validator {
Scope(Scope),
All(Sized<Validators>),
Any(Sized<Validators>),
Not(Sized<Validators>),
}
Expand description
A validator is a way to check if an array of scopes matches a predicate.
Can be constructed easily with the validator! macro.
§Examples
use twitch_oauth2::{validator, AppAccessToken, Scope, TwitchToken as _};
let token: AppAccessToken = token();
let validator = validator!(Scope::ChatEdit, Scope::ChatRead);
assert!(validator.matches(token.scopes()));
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Scope(Scope)
A scope
All(Sized<Validators>)
Matches true if all validators passed inside return true
Any(Sized<Validators>)
Matches true if any validator passed inside returns true
Not(Sized<Validators>)
Matches true if all validators passed inside matches false
Implementations§
Source§impl Validator
impl Validator
Sourcepub fn matches(&self, scopes: &[Scope]) -> bool
pub fn matches(&self, scopes: &[Scope]) -> bool
Checks if the given scopes match the predicate.
§Examples
use twitch_oauth2::{validator, Scope};
let scopes: &[Scope] = &[Scope::ChatEdit, Scope::ChatRead];
let validator = validator!(Scope::ChatEdit, Scope::ChatRead);
assert!(validator.matches(scopes));
assert!(!validator.matches(&scopes[..1]));
Sourcepub const fn scope(scope: Scope) -> Self
pub const fn scope(scope: Scope) -> Self
Create a Validator which matches if the scope is present.
Sourcepub const fn all_multiple(ands: &'static [Validator]) -> Self
pub const fn all_multiple(ands: &'static [Validator]) -> Self
Create a Validator which matches if all validators passed inside matches true.
Sourcepub const fn any_multiple(anys: &'static [Validator]) -> Self
pub const fn any_multiple(anys: &'static [Validator]) -> Self
Create a Validator which matches if any validator passed inside matches true.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Validator
impl RefUnwindSafe for Validator
impl Send for Validator
impl Sync for Validator
impl Unpin for Validator
impl UnwindSafe for Validator
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)