pub struct Resource<K, T, E>(/* private fields */);Expand description
A shared handle to one owned read, with no Clone bound on data or errors.
Dropping its last handle cancels the read and detaches its key subscription.
Cloned handles cannot extend the owner’s lifetime.
Implementations§
Source§impl<K: Clone + PartialEq + 'static, T: 'static, E: 'static> Resource<K, T, E>
impl<K: Clone + PartialEq + 'static, T: 'static, E: 'static> Resource<K, T, E>
Sourcepub fn new<F: Future<Output = Result<T, E>> + 'static>(
owner: &OwnerHandle,
key: impl Fn() -> Option<K> + 'static,
load: impl Fn(K, CancellationToken) -> F + 'static,
spawn: impl Fn(LocalBoxFuture<'static, ()>) + 'static,
) -> Self
pub fn new<F: Future<Output = Result<T, E>> + 'static>( owner: &OwnerHandle, key: impl Fn() -> Option<K> + 'static, load: impl Fn(K, CancellationToken) -> F + 'static, spawn: impl Fn(LocalBoxFuture<'static, ()>) + 'static, ) -> Self
spawn must schedule the future on a local executor. The loader is first
called when the scheduled future is polled after owner activation.
Return None from key to disable loading and clear previous data.
Like Self::new, with a loader and spawner shared by other reads,
such as the entries of one query cache.
pub fn get(&self) -> ResourceState<K, T, E>
pub fn with<R>(&self, read: impl FnOnce(&ResourceState<K, T, E>) -> R) -> R
Trait Implementations§
Auto Trait Implementations§
impl<K, T, E> !RefUnwindSafe for Resource<K, T, E>
impl<K, T, E> !Send for Resource<K, T, E>
impl<K, T, E> !Sync for Resource<K, T, E>
impl<K, T, E> !UnwindSafe for Resource<K, T, E>
impl<K, T, E> Freeze for Resource<K, T, E>
impl<K, T, E> Unpin for Resource<K, T, E>
impl<K, T, E> UnsafeUnpin for Resource<K, T, E>where
Rc<Inner<K, T, E>>: UnsafeUnpin,
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