pub struct Registry<T: Resource, I: TypedId, F: IdentityHandlerFactory<I>> {
identity: F::Filter,
pub(crate) data: RwLock<Storage<T, I>>,
backend: Backend,
}
Fields§
§identity: F::Filter
§data: RwLock<Storage<T, I>>
§backend: Backend
Implementations§
source§impl<T: Resource, I: TypedId + Copy, F: IdentityHandlerFactory<I>> Registry<T, I, F>
impl<T: Resource, I: TypedId + Copy, F: IdentityHandlerFactory<I>> Registry<T, I, F>
pub(crate) fn prepare( &self, id_in: <F::Filter as IdentityHandler<I>>::Input ) -> FutureId<'_, I, T>
sourcepub(crate) fn read<'a, A: Access<T>>(
&'a self,
_token: &'a mut Token<'_, A>
) -> (RwLockReadGuard<'a, Storage<T, I>>, Token<'a, T>)
pub(crate) fn read<'a, A: Access<T>>( &'a self, _token: &'a mut Token<'_, A> ) -> (RwLockReadGuard<'a, Storage<T, I>>, Token<'a, T>)
Acquire read access to this Registry
’s contents.
The caller must present a mutable reference to a Token<A>
,
for some type A
that comes before this Registry
’s resource
type T
in the lock ordering. A Token<Root>
grants
permission to lock any field; see Token::root
.
Once the read lock is acquired, return a new Token<T>
, along
with a read guard for this Registry
’s Storage
, which can
be indexed by id to get at the actual resources.
The borrow checker ensures that the caller cannot again access
its Token<A>
until it has dropped both the guard and the
Token<T>
.
See the Hub
type for more details on locking.
sourcepub(crate) fn write<'a, A: Access<T>>(
&'a self,
_token: &'a mut Token<'_, A>
) -> (RwLockWriteGuard<'a, Storage<T, I>>, Token<'a, T>)
pub(crate) fn write<'a, A: Access<T>>( &'a self, _token: &'a mut Token<'_, A> ) -> (RwLockWriteGuard<'a, Storage<T, I>>, Token<'a, T>)
Acquire write access to this Registry
’s contents.
The caller must present a mutable reference to a Token<A>
,
for some type A
that comes before this Registry
’s resource
type T
in the lock ordering. A Token<Root>
grants
permission to lock any field; see Token::root
.
Once the lock is acquired, return a new Token<T>
, along with
a write guard for this Registry
’s Storage
, which can be
indexed by id to get at the actual resources.
The borrow checker ensures that the caller cannot again access
its Token<A>
until it has dropped both the guard and the
Token<T>
.
See the Hub
type for more details on locking.
sourcepub fn unregister_locked(&self, id: I, guard: &mut Storage<T, I>) -> Option<T>
pub fn unregister_locked(&self, id: I, guard: &mut Storage<T, I>) -> Option<T>
Unregister the resource at id
.
The caller must prove that it already holds a write lock for
this Registry
by passing a mutable reference to this
Registry
’s storage, obtained from the write guard returned
by a previous call to write
, as the guard
parameter.
sourcepub(crate) fn unregister<'a, A: Access<T>>(
&self,
id: I,
_token: &'a mut Token<'_, A>
) -> (Option<T>, Token<'a, T>)
pub(crate) fn unregister<'a, A: Access<T>>( &self, id: I, _token: &'a mut Token<'_, A> ) -> (Option<T>, Token<'a, T>)
Unregister the resource at id
and return its value, if any.
The caller must present a mutable reference to a Token<A>
,
for some type A
that comes before this Registry
’s resource
type T
in the lock ordering.
This returns a Token<T>
, but it’s almost useless, because it
doesn’t return a lock guard to go with it: its only effect is
to make the token you passed to this function inaccessible.
However, the Token<T>
can be used to satisfy some functions’
bureacratic expectations that you will have one available.
The borrow checker ensures that the caller cannot again access
its Token<A>
until it has dropped both the guard and the
Token<T>
.
See the Hub
type for more details on locking.