pub struct Capability { /* private fields */ }Expand description
A single capability: a scope and the allowed actions within it.
The wire/string representation is "<scope>:<actions>", see module docs.
Implementations§
Source§impl Capability
impl Capability
Sourcepub fn root() -> Capability
pub fn root() -> Capability
Shorthand for a root capability at / with read+write.
Equivalent to a capability with scope / and both read and write actions.
use pubky_common::capabilities::Capability;
assert_eq!(Capability::root().to_string(), "/:rw");Sourcepub fn read(scope: impl AsRef<str>) -> Result<Capability, CapabilityParseError>
pub fn read(scope: impl AsRef<str>) -> Result<Capability, CapabilityParseError>
Construct a read-only capability for scope.
use pubky_common::capabilities::Capability;
assert_eq!(Capability::read("/pub/my.app").unwrap().to_string(), "/pub/my.app:r");Sourcepub fn write(scope: impl AsRef<str>) -> Result<Capability, CapabilityParseError>
pub fn write(scope: impl AsRef<str>) -> Result<Capability, CapabilityParseError>
Construct a write-only capability for scope.
use pubky_common::capabilities::Capability;
assert_eq!(Capability::write("/pub/tmp").unwrap().to_string(), "/pub/tmp:w");Sourcepub fn read_write(
scope: impl AsRef<str>,
) -> Result<Capability, CapabilityParseError>
pub fn read_write( scope: impl AsRef<str>, ) -> Result<Capability, CapabilityParseError>
Construct a read+write capability for scope.
use pubky_common::capabilities::Capability;
assert_eq!(Capability::read_write("/").unwrap().to_string(), "/:rw");Sourcepub fn scope(&self) -> &StoragePath
pub fn scope(&self) -> &StoragePath
Return the resource scope covered by this capability.
Sourcepub fn scope_covers_path(&self, path: &StoragePath) -> bool
pub fn scope_covers_path(&self, path: &StoragePath) -> bool
Whether this capability’s scope covers the given path.
The trailing / on a scope is significant — it distinguishes a
directory scope from a file scope:
- Directory scope (ends in
/): covers the directory itself and any path inside it./pub/app/covers/pub/app/,/pub/app/foo, and/pub/app/sub/bar, but NOT/pub/appor/pub/app-evil/foo. - File scope (no trailing
/): covers only the exact path./pub/appcovers/pub/appand nothing else — not/pub/app/foo(that’s inside the directory/pub/app/, a different resource) and not/pub/app-evil(no prefix-as-string matching).
Trait Implementations§
Source§impl Clone for Capability
impl Clone for Capability
Source§fn clone(&self) -> Capability
fn clone(&self) -> Capability
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Capability
impl Debug for Capability
Source§impl<'de> Deserialize<'de> for Capability
impl<'de> Deserialize<'de> for Capability
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Capability, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Capability, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for Capability
impl Display for Capability
impl Eq for Capability
Source§impl FromStr for Capability
impl FromStr for Capability
Source§fn from_str(value: &str) -> Result<Capability, <Capability as FromStr>::Err>
fn from_str(value: &str) -> Result<Capability, <Capability as FromStr>::Err>
Parse "<scope>:<actions>".
use pubky_common::capabilities::Capability;
let capability: Capability = "/pub/my-cool-app/:rw".parse().unwrap();
assert_eq!(capability.to_string(), "/pub/my-cool-app/:rw");Source§type Err = CapabilityParseError
type Err = CapabilityParseError
The associated error which can be returned from parsing.
Source§impl PartialEq for Capability
impl PartialEq for Capability
Source§impl Serialize for Capability
impl Serialize for Capability
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl StructuralPartialEq for Capability
Source§impl TryFrom<&str> for Capability
impl TryFrom<&str> for Capability
Source§type Error = CapabilityParseError
type Error = CapabilityParseError
The type returned in the event of a conversion error.
Source§fn try_from(
value: &str,
) -> Result<Capability, <Capability as TryFrom<&str>>::Error>
fn try_from( value: &str, ) -> Result<Capability, <Capability as TryFrom<&str>>::Error>
Performs the conversion.
Source§impl TryFrom<String> for Capability
impl TryFrom<String> for Capability
Source§type Error = CapabilityParseError
type Error = CapabilityParseError
The type returned in the event of a conversion error.
Source§fn try_from(
value: String,
) -> Result<Capability, <Capability as TryFrom<String>>::Error>
fn try_from( value: String, ) -> Result<Capability, <Capability as TryFrom<String>>::Error>
Performs the conversion.
Auto Trait Implementations§
impl Freeze for Capability
impl RefUnwindSafe for Capability
impl Send for Capability
impl Sync for Capability
impl Unpin for Capability
impl UnsafeUnpin for Capability
impl UnwindSafe for Capability
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