Skip to main content

Scope

Enum Scope 

Source
pub enum Scope {
    Atproto,
    Transition(Transition),
    Repo {
        collection: NsidPattern,
        actions: ActionSet,
    },
    Rpc {
        method: NsidPattern,
        aud: Option<String>,
    },
    Blob {
        accept: Vec<MimePattern>,
    },
    Identity {
        attr: IdentityAttr,
    },
    Account {
        attr: AccountAttr,
        action: AccountAction,
    },
    Include {
        nsid: String,
        aud: Option<String>,
    },
    Unknown(String),
}
Expand description

One parsed scope atom.

Variants§

§

Atproto

The base atproto scope every grant carries.

§

Transition(Transition)

A legacy transition:* scope.

§

Repo

repo:<collection>[?action=...].

Fields

§collection: NsidPattern

The collection this scope covers, exact or wildcard.

§actions: ActionSet

Which write actions are covered.

§

Rpc

rpc:<lxm>[?aud=...].

Fields

§method: NsidPattern

The XRPC method this scope covers, exact or wildcard.

§aud: Option<String>

The audience this scope is bound to, percent-decoded: a DID, a DID and a service fragment, or * for every audience.

§

Blob

blob:<mime> or blob?accept=<mime>[&accept=<mime>…].

Fields

§accept: Vec<MimePattern>

The MIME types this scope covers, exact or wildcard. Sorted, deduplicated, and never empty — see Scope::blob.

§

Identity

identity:<attr>. This server never grants one; see plan/scope-policy.md.

Fields

§attr: IdentityAttr

The part of the account’s identity this scope names.

§

Account

account:<attr>[?action=...]. Never granted either.

Fields

§attr: AccountAttr

The part of the account’s hosting this scope names.

§action: AccountAction

How much control over it this scope grants.

§

Include

include:<nsid>[?aud=...] — a permission set. As an atom it admits only itself; crate::Include reads what it grants.

Fields

§nsid: String

The set’s name, percent-decoded. crate::Include::new says whether it names a set at all.

§aud: Option<String>

The audience the set’s inheritAud permissions take, percent-decoded.

§

Unknown(String)

An atom this grammar cannot read as any scope above: an unknown kind, such as space:*, or a value its kind does not define, such as account:status. Kept as written, it admits only itself.

Implementations§

Source§

impl Scope

Source

pub fn parse(atom: &str) -> Result<Self, ScopeParseError>

Parses an atom that names one scope, such as repo:app.bsky.feed.post?action=create, whatever its form’s warnings.

An atom that lists several collections or methods names a scope for each, and ScopeSet::parse is what reads it. So does an atom this grammar cannot read, which ScopeSet::parse keeps as Scope::Unknown and this refuses.

Source

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

Does self admit every request that other admits?

Reflexive and used both directions by ScopeSet::intersect: a ceiling contains a requested scope, or a requested scope is itself a (possibly equal) subset of the ceiling’s scope.

Source

pub fn intersect(&self, other: &Scope) -> Option<Scope>

The most specific scope both self and other admit in common, if their admitted requests overlap at all.

None is a real refusal, not an error: it means the two scopes name disjoint capabilities (a repo: ceiling for one collection against a request for a different one, say), and the caller — scope-policy’s ceiling check — is expected to report that by name.

Source

pub fn repo_write(collection: &str, action: Action) -> Scope

The repo: scope one record write needs: action on exactly collection.

Source

pub fn blob(accept: Vec<MimePattern>) -> Scope

A blob: scope over accept, canonical: sorted, deduplicated, and with any pattern another one already covers dropped, so blob?accept=image/*&accept=image/png is blob:image/*.

§Panics

If accept is empty. Every caller builds it from something.

Source

pub fn blob_upload(mime_type: &str) -> Scope

The blob: scope one upload needs: the type it declared.

The type is taken up to any ; — image/png; charset=binary is an upload of image/png — and one that is not type/subtype at all is taken as application/octet-stream, which is what an unreadable content type means anyway.

Source

pub(crate) fn kind(&self) -> u8

The variant this atom is, for ScopeSet::narrow’s same-kind rule.

Not PartialEq on the whole scope and not a public type: the only question asked of it is whether two atoms are the same kind of capability, and giving that a name is cheaper than matching on eight variants at the one call site.

Trait Implementations§

Source§

impl Clone for Scope

Source§

fn clone(&self) -> Scope

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Scope

Source§

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

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

impl Display for Scope

Source§

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

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

impl Ord for Scope

Source§

fn cmp(&self, other: &Scope) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Scope

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialOrd for Scope

Source§

fn partial_cmp(&self, other: &Scope) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Scope

Source§

impl StructuralPartialEq for Scope

Auto Trait Implementations§

§

impl Freeze for Scope

§

impl RefUnwindSafe for Scope

§

impl Send for Scope

§

impl Sync for Scope

§

impl Unpin for Scope

§

impl UnsafeUnpin for Scope

§

impl UnwindSafe for Scope

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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<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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.