pub struct ResourceScope(/* private fields */);Expand description
A program tree’s slot for its host’s ResourceAccessor.
Cloning a scope yields another handle to the same slot, which is how
every program and kernel of one tree shares it. An accessor is
installed at most once per scope. A scope with none installed
resolves a lookup through the parent it joined
(Self::join), and answers None when it joined none, which is
the norm for a program that runs without a host.
Implementations§
Source§impl ResourceScope
impl ResourceScope
Sourcepub fn with_accessor(accessor: Arc<dyn ResourceAccessor>) -> Self
pub fn with_accessor(accessor: Arc<dyn ResourceAccessor>) -> Self
A scope with accessor already installed.
Sourcepub fn install(
&self,
accessor: Arc<dyn ResourceAccessor>,
) -> Result<(), Arc<dyn ResourceAccessor>>
pub fn install( &self, accessor: Arc<dyn ResourceAccessor>, ) -> Result<(), Arc<dyn ResourceAccessor>>
Install accessor for every program and kernel of this tree.
A scope has one accessor for its life: when one is already
installed the call returns accessor back as the error and the
installed one stays. An accessor installed here takes precedence
over the parent the scope joined.
Sourcepub fn is_installed(&self) -> bool
pub fn is_installed(&self) -> bool
Whether an accessor is installed on this scope itself. A scope
that resolves through its parent reports false.
Sourcepub fn parent(&self) -> Option<&ResourceScope>
pub fn parent(&self) -> Option<&ResourceScope>
The parent this scope delegates to, when it joined one.
Sourcepub fn join(&self, parent: &ResourceScope) -> Result<(), ScopeJoinError>
pub fn join(&self, parent: &ResourceScope) -> Result<(), ScopeJoinError>
Join this scope to parent, so that while no accessor is
installed here, lookups resolve through parent. Binding a
kernel under a parent kernel (crate::kernel::bind_under)
joins the child program’s scope to the parent’s.
A scope joins at most one parent, the first it is joined to, and keeps it for its life. The join changes nothing when:
- this scope has an accessor installed, which it keeps;
parentis this scope, or already resolves through it (this scope isparent’s ancestor), so joining would make a scope delegate to itself;- this scope already joined a parent,
parentor another. The first join wins: a node holds its program’s one scope, so a program whose kernels are bound under two trees resolves through the first. A host that binds one program under trees with different accessors installs one on the program itself.
Otherwise this scope joins parent. The one error is a join
that raced others into a cycle (ScopeJoinError::Cycle).
Sourcepub fn lookup(&self, key: &str) -> Option<Arc<dyn Any + Send + Sync>>
pub fn lookup(&self, key: &str) -> Option<Arc<dyn Any + Send + Sync>>
Look up an already-attached resource’s accessor payload by
fingerprint key: through this scope’s accessor when one is
installed, and otherwise through the parent it joined.
Returns None when no scope on the way has an accessor or when
the accessor that answers holds no live entry under key. The
lookup is synchronous and never blocks.
Sourcepub fn same_scope(&self, other: &ResourceScope) -> bool
pub fn same_scope(&self, other: &ResourceScope) -> bool
Whether self and other are handles to one scope.
Trait Implementations§
Source§impl Clone for ResourceScope
impl Clone for ResourceScope
Source§impl Debug for ResourceScope
impl Debug for ResourceScope
Auto Trait Implementations§
impl !RefUnwindSafe for ResourceScope
impl !UnwindSafe for ResourceScope
impl Freeze for ResourceScope
impl Send for ResourceScope
impl Sync for ResourceScope
impl Unpin for ResourceScope
impl UnsafeUnpin for ResourceScope
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> 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