Skip to main content

Resource

Struct Resource 

Source
pub struct Resource<T: 'static, E: 'static> { /* private fields */ }
Expand description

Data loaded asynchronously: resource or resource_on.

It fetches when created, again whenever its source changes, and on refetch. A new fetch cancels the one in flight. While it loads, the previous data stays available; an error keeps it too, so a view can show both.

Implementations§

Source§

impl<T: 'static, E: 'static> Resource<T, E>

Source

pub fn loading(&self) -> bool

Whether a fetch is in flight.

Source

pub fn data(&self) -> Option<T>
where T: Clone,

The last data loaded, if any.

Source

pub fn with_data<R>(&self, f: impl FnOnce(Option<&T>) -> R) -> R

Borrows the last data loaded.

Source

pub fn error(&self) -> Option<E>
where E: Clone,

The error of the last fetch, if it failed.

Source

pub fn with_error<R>(&self, f: impl FnOnce(Option<&E>) -> R) -> R

Borrows the error of the last fetch, if it failed.

Source

pub fn refetch(&self)

Fetches again with the current source.

Source

pub fn set_data(&self, value: T)

Replaces the data locally, e.g. optimistically after a change the server will confirm on the next fetch.

Trait Implementations§

Source§

impl<T: 'static, E: 'static> Clone for Resource<T, E>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: 'static, E: 'static> Copy for Resource<T, E>

Auto Trait Implementations§

§

impl<T, E> Forget for Resource<T, E>

§

impl<T, E> Freeze for Resource<T, E>

§

impl<T, E> Move for Resource<T, E>

§

impl<T, E> RefUnwindSafe for Resource<T, E>

§

impl<T, E> Send for Resource<T, E>
where NonZero<u32>: Send,

§

impl<T, E> Sync for Resource<T, E>
where NonZero<u32>: Sync,

§

impl<T, E> Unpin for Resource<T, E>
where NonZero<u32>: Unpin,

§

impl<T, E> UnsafeUnpin for Resource<T, E>

§

impl<T, E> UnwindSafe for Resource<T, E>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.