pub struct Capability {
pub scope: String,
pub actions: Vec<Action>,
}Expand description
A single capability: a scope and the allowed actions within it.
The wire/string representation is "<scope>:<actions>", see module docs.
Fields§
§scope: StringScope of resources (e.g. a directory or file). Must start with /.
actions: Vec<Action>Allowed actions within scope. Serialized as a compact action string (e.g. "rw").
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 Capability { scope: "/".into(), actions: vec![Read, Write] }.
use pubky_common::capabilities::Capability;
assert_eq!(Capability::root().to_string(), "/:rw");Sourcepub fn read<S>(scope: S) -> Capability
pub fn read<S>(scope: S) -> Capability
Construct a read-only capability for scope.
The scope is normalized to start with / if it does not already.
use pubky_common::capabilities::Capability;
assert_eq!(Capability::read("pub/my.app").to_string(), "/pub/my.app:r");Sourcepub fn write<S>(scope: S) -> Capability
pub fn write<S>(scope: S) -> Capability
Construct a write-only capability for scope.
use pubky_common::capabilities::Capability;
assert_eq!(Capability::write("/pub/tmp").to_string(), "/pub/tmp:w");Sourcepub fn read_write<S>(scope: S) -> Capability
pub fn read_write<S>(scope: S) -> Capability
Construct a read+write capability for scope.
use pubky_common::capabilities::Capability;
assert_eq!(Capability::read_write("/").to_string(), "/:rw");Sourcepub fn builder<S>(scope: S) -> CapabilityBuilder
pub fn builder<S>(scope: S) -> CapabilityBuilder
Start building a single capability for scope.
The scope is normalized to have a leading /.
use pubky_common::capabilities::Capability;
let cap = Capability::builder("pub/my.app").read().finish();
assert_eq!(cap.to_string(), "/pub/my.app:r");Trait Implementations§
Source§impl Clone for Capability
impl Clone for Capability
Source§fn clone(&self) -> Capability
fn clone(&self) -> Capability
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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>,
Source§impl Display for Capability
impl Display for Capability
Source§impl FromStr for Capability
impl FromStr for Capability
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,
Source§impl TryFrom<&str> for Capability
impl TryFrom<&str> for Capability
Source§fn try_from(value: &str) -> Result<Capability, Error>
fn try_from(value: &str) -> Result<Capability, Error>
Parse "<scope>:<actions>". Scope must start with /; actions must be valid letters.
use pubky_common::capabilities::Capability;
let cap: Capability = "/pub/my-cool-app/:rw".try_into().unwrap();
assert_eq!(cap.to_string(), "/pub/my-cool-app/:rw");Source§impl TryFrom<String> for Capability
impl TryFrom<String> for Capability
impl Eq for Capability
impl StructuralPartialEq for Capability
Auto Trait Implementations§
impl Freeze for Capability
impl RefUnwindSafe for Capability
impl Send for Capability
impl Sync for Capability
impl Unpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.