pub struct Scopes(/* private fields */);Expand description
What a token is allowed to do.
A plain list of strings, compared exactly. It is deliberately not an enum and deliberately not tied to any other package: an application names its own scopes, and a framework that ships a fixed vocabulary is a framework you fight the first time you add a feature.
Implementations§
Source§impl Scopes
impl Scopes
Sourcepub fn any() -> Self
pub fn any() -> Self
The wildcard: everything this user can do.
Sanctum’s default, and the right one for a first-party mobile app that is simply the user on another device.
Sourcepub fn with(self, scope: impl Into<String>) -> Self
pub fn with(self, scope: impl Into<String>) -> Self
Add one scope, for chaining: Scopes::new().with("posts:read").
Sourcepub fn can(&self, scope: &str) -> bool
pub fn can(&self, scope: &str) -> bool
Whether this list grants scope.
The match is exact, apart from the wildcard. posts:write does not
grant posts:writeextra and does not grant posts:write:all: a prefix
match here would mean that adding a narrower-sounding scope later
silently hands it to every token that already held the shorter one.