pub struct Dict { /* private fields */ }
Expand description
A capability that represents a dictionary of capabilities.
Implementations§
Source§impl Dict
impl Dict
Sourcepub fn new_with_not_found(
not_found: impl Fn(&str) + 'static + Send + Sync,
) -> Self
pub fn new_with_not_found( not_found: impl Fn(&str) + 'static + Send + Sync, ) -> Self
Creates an empty dictionary. When an external request tries to access a non-existent entry,
the name of the entry will be sent using not_found
.
Sourcepub fn register_update_notifier(&self, notifier_fn: UpdateNotifierFn)
pub fn register_update_notifier(&self, notifier_fn: UpdateNotifierFn)
Registers a new update notifier function with this dictionary. The function will be called
whenever an entry is added to or removed from this dictionary. The function will be
immediately called with an EntryUpdate::Add
value for any entries already in this
dictionary.
Note that this function will be called while the internal dictionary structure is locked, so it must not interact with the dictionary on which it is registered. It shouldn’t even hold a strong reference to the dictionary it’s registered on, as that’ll create a cycle and make LSAN sad.
Sourcepub fn insert(
&self,
key: Key,
capability: Capability,
) -> Result<(), CapabilityStoreError>
pub fn insert( &self, key: Key, capability: Capability, ) -> Result<(), CapabilityStoreError>
Inserts an entry, mapping key
to capability
. If an entry already exists at key
, a
fsandbox::DictionaryError::AlreadyExists
will be returned.
pub fn append(&self, other: &Dict) -> Result<(), ()>
Sourcepub fn get<Q>(&self, key: &Q) -> Result<Option<Capability>, ()>
pub fn get<Q>(&self, key: &Q) -> Result<Option<Capability>, ()>
Returns a clone of the capability associated with key
. If there is no entry for key
,
None
is returned.
If the value could not be cloned, returns an error.
Sourcepub fn get_or_insert(
&self,
key: &Key,
default: impl FnOnce() -> Capability,
) -> Result<Capability, ()>
pub fn get_or_insert( &self, key: &Key, default: impl FnOnce() -> Capability, ) -> Result<Capability, ()>
Returns a clone of the capability associated with key
, or populates it with default
if
it is not present.
If the value could not be cloned, returns an error.
Sourcepub fn remove(&self, key: &BorrowedName) -> Option<Capability>
pub fn remove(&self, key: &BorrowedName) -> Option<Capability>
Removes key
from the entries, returning the capability at key
if the key was already in
the entries.
Sourcepub fn enumerate(
&self,
) -> impl Iterator<Item = (Key, Result<Capability, ()>)> + use<>
pub fn enumerate( &self, ) -> impl Iterator<Item = (Key, Result<Capability, ()>)> + use<>
Returns an iterator over a clone of the entries, sorted by key.
If a capability is not cloneable, an error returned for the value.
Sourcepub fn keys(&self) -> impl Iterator<Item = Key> + use<>
pub fn keys(&self) -> impl Iterator<Item = Key> + use<>
Returns an iterator over the keys, in sorted order.
Sourcepub fn drain(&self) -> impl Iterator<Item = (Key, Capability)> + use<>
pub fn drain(&self) -> impl Iterator<Item = (Key, Capability)> + use<>
Removes all entries from the Dict and returns them as an iterator.
Sourcepub fn shallow_copy(&self) -> Result<Self, ()>
pub fn shallow_copy(&self) -> Result<Self, ()>
Creates a new Dict with entries cloned from this Dict.
This is a shallow copy. Values are cloned, not copied, so are new references to the same underlying data.
If any value in the dictionary could not be cloned, returns an error.
Source§impl Dict
impl Dict
Sourcepub fn try_into_directory_entry_oneshot(
self,
scope: ExecutionScope,
) -> Result<Arc<dyn DirectoryEntry>, ConversionError>
pub fn try_into_directory_entry_oneshot( self, scope: ExecutionScope, ) -> Result<Arc<dyn DirectoryEntry>, ConversionError>
Like RemotableCapability::try_into_directory_entry, but this version actually consumes
the contents of the Dict. In other words, if this function returns Ok
, self
will
be empty. If any items are added to self
later, they will not appear in the directory.
This method is useful when the caller has no need to keep the original Dict. Note
that even if there is only one reference to the Dict, calling
RemotableCapability::try_into_directory_entry does not have the same effect because the
vfs
keeps alive reference to the Dict – see the comment in the implementation.
This is transitive: any Dicts nested in this one will be consumed as well.
Trait Implementations§
Source§impl CapabilityBound for Dict
impl CapabilityBound for Dict
fn debug_typename() -> &'static str
Source§impl From<Dict> for Capability
impl From<Dict> for Capability
Source§impl From<Dict> for Capability
impl From<Dict> for Capability
Source§impl From<Dict> for DictionaryRef
impl From<Dict> for DictionaryRef
Source§impl FromEnum<Capability> for Dict
impl FromEnum<Capability> for Dict
fn from_enum(e: &Capability) -> Option<&Self>
Source§impl RemotableCapability for Dict
impl RemotableCapability for Dict
Source§fn try_into_directory_entry(
self,
scope: ExecutionScope,
) -> Result<Arc<dyn DirectoryEntry>, ConversionError>
fn try_into_directory_entry( self, scope: ExecutionScope, ) -> Result<Arc<dyn DirectoryEntry>, ConversionError>
self
to a DirectoryEntry which can be served in a
VFS. Read moreSource§impl TryFrom<Capability> for Dict
impl TryFrom<Capability> for Dict
Source§impl TryFrom<DictionaryRef> for Dict
impl TryFrom<DictionaryRef> for Dict
Source§type Error = RemoteError
type Error = RemoteError
Auto Trait Implementations§
impl Freeze for Dict
impl RefUnwindSafe for Dict
impl Send for Dict
impl Sync for Dict
impl Unpin for Dict
impl UnwindSafe for Dict
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, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
Source§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more