Resource

Struct Resource 

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

A handle to a reactive future spawned with use_resource that can be used to modify or read the result of the future.

§Example

Reading the result of a resource:

fn App() -> Element {
    let mut revision = use_signal(|| "1d03b42");
    let mut resource = use_resource(move || async move {
        // This will run every time the revision signal changes because we read the count inside the future
        reqwest::get(format!("https://github.com/DioxusLabs/awesome-dioxus/blob/{revision}/awesome.json")).await
    });

    // Since our resource may not be ready yet, the value is an Option. Our request may also fail, so the get function returns a Result
    // The complete type we need to match is `Option<Result<String, reqwest::Error>>`
    // We can use `read_unchecked` to keep our matching code in one statement while avoiding a temporary variable error (this is still completely safe because dioxus checks the borrows at runtime)
    match &*resource.read_unchecked() {
        Some(Ok(value)) => rsx! { "{value:?}" },
        Some(Err(err)) => rsx! { "Error: {err}" },
        None => rsx! { "Loading..." },
    }
}

Implementations§

Source§

impl<T> Resource<T>

Source

pub fn restart(&mut self)

Restart the resource’s future.

This will cancel the current future and start a new one.

§Example
fn App() -> Element {
    let mut revision = use_signal(|| "1d03b42");
    let mut resource = use_resource(move || async move {
        // This will run every time the revision signal changes because we read the count inside the future
        reqwest::get(format!("https://github.com/DioxusLabs/awesome-dioxus/blob/{revision}/awesome.json")).await
    });

    rsx! {
        button {
            // We can get a signal with the value of the resource with the `value` method
            onclick: move |_| resource.restart(),
            "Restart resource"
        }
        "{resource:?}"
    }
}
Source

pub fn cancel(&mut self)

Forcefully cancel the resource’s future.

§Example
fn App() -> Element {
    let mut revision = use_signal(|| "1d03b42");
    let mut resource = use_resource(move || async move {
        reqwest::get(format!("https://github.com/DioxusLabs/awesome-dioxus/blob/{revision}/awesome.json")).await
    });

    rsx! {
        button {
            // We can cancel the resource before it finishes with the `cancel` method
            onclick: move |_| resource.cancel(),
            "Cancel resource"
        }
        "{resource:?}"
    }
}
Source

pub fn pause(&mut self)

Pause the resource’s future.

§Example
fn App() -> Element {
    let mut revision = use_signal(|| "1d03b42");
    let mut resource = use_resource(move || async move {
        // This will run every time the revision signal changes because we read the count inside the future
        reqwest::get(format!("https://github.com/DioxusLabs/awesome-dioxus/blob/{revision}/awesome.json")).await
    });

    rsx! {
        button {
            // We can pause the future with the `pause` method
            onclick: move |_| resource.pause(),
            "Pause"
        }
        button {
            // And resume it with the `resume` method
            onclick: move |_| resource.resume(),
            "Resume"
        }
        "{resource:?}"
    }
}
Source

pub fn resume(&mut self)

Resume the resource’s future.

§Example
fn App() -> Element {
    let mut revision = use_signal(|| "1d03b42");
    let mut resource = use_resource(move || async move {
        // This will run every time the revision signal changes because we read the count inside the future
        reqwest::get(format!("https://github.com/DioxusLabs/awesome-dioxus/blob/{revision}/awesome.json")).await
    });

    rsx! {
        button {
            // We can pause the future with the `pause` method
            onclick: move |_| resource.pause(),
            "Pause"
        }
        button {
            // And resume it with the `resume` method
            onclick: move |_| resource.resume(),
            "Resume"
        }
        "{resource:?}"
    }
}
Source

pub fn clear(&mut self)

Clear the resource’s value. This will just reset the value. It will not modify any running tasks.

§Example
fn App() -> Element {
    let mut revision = use_signal(|| "1d03b42");
    let mut resource = use_resource(move || async move {
        // This will run every time the revision signal changes because we read the count inside the future
        reqwest::get(format!("https://github.com/DioxusLabs/awesome-dioxus/blob/{revision}/awesome.json")).await
    });

    rsx! {
        button {
            // We clear the value without modifying any running tasks with the `clear` method
            onclick: move |_| resource.clear(),
            "Clear"
        }
        "{resource:?}"
    }
}
Source

pub fn task(&self) -> Task

Get a handle to the inner task backing this resource Modify the task through this handle will cause inconsistent state

Source

pub fn pending(&self) -> bool

Is the resource’s future currently running?

Source

pub fn finished(&self) -> bool

Is the resource’s future currently finished running?

Reading this does not subscribe to the future’s state

§Example
fn App() -> Element {
    let mut revision = use_signal(|| "1d03b42");
    let mut resource = use_resource(move || async move {
        // This will run every time the revision signal changes because we read the count inside the future
        reqwest::get(format!("https://github.com/DioxusLabs/awesome-dioxus/blob/{revision}/awesome.json")).await
    });

    // We can use the `finished` method to check if the future is finished
    if resource.finished() {
        rsx! {
            "The resource is finished"
        }
    } else {
        rsx! {
            "The resource is still running"
        }
    }
}
Source

pub fn state(&self) -> ReadSignal<UseResourceState>

Get the current state of the resource’s future. This method returns a ReadSignal which can be read to get the current state of the resource or passed to other hooks and components.

§Example
fn App() -> Element {
    let mut revision = use_signal(|| "1d03b42");
    let mut resource = use_resource(move || async move {
        // This will run every time the revision signal changes because we read the count inside the future
        reqwest::get(format!("https://github.com/DioxusLabs/awesome-dioxus/blob/{revision}/awesome.json")).await
    });

    // We can read the current state of the future with the `state` method
    match resource.state().cloned() {
        UseResourceState::Pending => rsx! {
            "The resource is still pending"
        },
        UseResourceState::Paused => rsx! {
            "The resource has been paused"
        },
        UseResourceState::Stopped => rsx! {
            "The resource has been stopped"
        },
        UseResourceState::Ready => rsx! {
            "The resource is ready!"
        },
    }
}
Source

pub fn value(&self) -> ReadSignal<Option<T>>

Get the current value of the resource’s future. This method returns a ReadSignal which can be read to get the current value of the resource or passed to other hooks and components.

§Example
fn App() -> Element {
    let mut revision = use_signal(|| "1d03b42");
    let mut resource = use_resource(move || async move {
        // This will run every time the revision signal changes because we read the count inside the future
        reqwest::get(format!("https://github.com/DioxusLabs/awesome-dioxus/blob/{revision}/awesome.json")).await
    });

    // We can get a signal with the value of the resource with the `value` method
    let value = resource.value();

    // Since our resource may not be ready yet, the value is an Option. Our request may also fail, so the get function returns a Result
    // The complete type we need to match is `Option<Result<String, reqwest::Error>>`
    // We can use `read_unchecked` to keep our matching code in one statement while avoiding a temporary variable error (this is still completely safe because dioxus checks the borrows at runtime)
    match &*value.read_unchecked() {
        Some(Ok(value)) => rsx! { "{value:?}" },
        Some(Err(err)) => rsx! { "Error: {err}" },
        None => rsx! { "Loading..." },
    }
}
Source

pub fn suspend(&self) -> Result<MappedSignal<T, Signal<Option<T>>>, RenderError>

Suspend the resource’s future and only continue rendering when the future is ready

Source§

impl<T, E> Resource<Result<T, E>>

Source

pub fn result( &self, ) -> Option<Result<MappedSignal<T, Signal<Option<Result<T, E>>>>, MappedSignal<E, Signal<Option<Result<T, E>>>>>>

Convert the Resource<Result<T, E>> into an Option<Result<MappedSignal<T>, MappedSignal<E>>>

Trait Implementations§

Source§

impl<T> Clone for Resource<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + 'static> Debug for Resource<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Clone> Deref for Resource<T>

Allow calling a signal with signal() syntax

Currently only limited to copy types, though could probably specialize for string/arc/rc

Source§

type Target = dyn Fn() -> Option<T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> From<Resource<T>> for ReadSignal<Option<T>>

Source§

fn from(val: Resource<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> Future for Resource<T>

Source§

type Output = ()

The type of value produced on completion.
Source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Attempts to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more
Source§

impl<T> IntoAttributeValue for Resource<T>

Source§

fn into_value(self) -> AttributeValue

Convert into an attribute value
Source§

impl<T> IntoDynNode for Resource<T>
where T: Clone + IntoDynNode,

Source§

fn into_dyn_node(self) -> DynamicNode

Consume this item and produce a DynamicNode
Source§

impl<T> PartialEq for Resource<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Readable for Resource<T>

Source§

type Target = Option<T>

The target type of the reference.
Source§

type Storage = UnsyncStorage

The type of the storage this readable uses.
Source§

fn try_read_unchecked(&self) -> Result<ReadableRef<'static, Self>, BorrowError>

Try to get a reference to the value without checking the lifetime. This will subscribe the current scope to the signal. Read more
Source§

fn try_peek_unchecked(&self) -> Result<ReadableRef<'static, Self>, BorrowError>

Try to peek the current value of the signal without subscribing to updates. If the value has been dropped, this will return an error. Read more
Source§

fn subscribers(&self) -> Subscribers

Get the underlying subscriber list for this readable. This is used to track when the value changes and notify subscribers.
Source§

impl<T> Writable for Resource<T>

Source§

type WriteMetadata = <Signal<Option<T>> as Writable>::WriteMetadata

Additional data associated with the write reference.
Source§

fn try_write_unchecked( &self, ) -> Result<WritableRef<'static, Self>, BorrowMutError>
where Self::Target: 'static,

Try to get a mutable reference to the value without checking the lifetime. This will update any subscribers. Read more
Source§

impl<T> Copy for Resource<T>

Auto Trait Implementations§

§

impl<T> Freeze for Resource<T>

§

impl<T> !RefUnwindSafe for Resource<T>

§

impl<T> !Send for Resource<T>

§

impl<T> !Sync for Resource<T>

§

impl<T> Unpin for Resource<T>
where T: Unpin,

§

impl<T> !UnwindSafe for Resource<T>

Blanket Implementations§

Source§

impl<F> AllowFutureExt for F
where F: Future,

Source§

fn allow<W>(self) -> AllowFuture<Self>
where W: Warning + ?Sized, Self: Sized,

Allow a lint while a future is running
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> FutureExt for T
where T: Future + ?Sized,

Source§

fn map<U, F>(self, f: F) -> Map<Self, F>
where F: FnOnce(Self::Output) -> U, Self: Sized,

Map this future’s output to a different type, returning a new future of the resulting type. Read more
Source§

fn map_into<U>(self) -> MapInto<Self, U>
where Self::Output: Into<U>, Self: Sized,

Map this future’s output to a different type, returning a new future of the resulting type. Read more
Source§

fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
where F: FnOnce(Self::Output) -> Fut, Fut: Future, Self: Sized,

Chain on a computation for when a future finished, passing the result of the future to the provided closure f. Read more
Source§

fn left_future<B>(self) -> Either<Self, B>
where B: Future<Output = Self::Output>, Self: Sized,

Wrap this future in an Either future, making it the left-hand variant of that Either. Read more
Source§

fn right_future<A>(self) -> Either<A, Self>
where A: Future<Output = Self::Output>, Self: Sized,

Wrap this future in an Either future, making it the right-hand variant of that Either. Read more
Source§

fn into_stream(self) -> IntoStream<Self>
where Self: Sized,

Convert this future into a single element stream. Read more
Source§

fn flatten(self) -> Flatten<Self>
where Self::Output: Future, Self: Sized,

Flatten the execution of this future when the output of this future is itself another future. Read more
Source§

fn flatten_stream(self) -> FlattenStream<Self>
where Self::Output: Stream, Self: Sized,

Flatten the execution of this future when the successful result of this future is a stream. Read more
Source§

fn fuse(self) -> Fuse<Self>
where Self: Sized,

Fuse a future such that poll will never again be called once it has completed. This method can be used to turn any Future into a FusedFuture. Read more
Source§

fn inspect<F>(self, f: F) -> Inspect<Self, F>
where F: FnOnce(&Self::Output), Self: Sized,

Do something with the output of a future before passing it on. Read more
Source§

fn catch_unwind(self) -> CatchUnwind<Self>
where Self: Sized + UnwindSafe,

Catches unwinding panics while polling the future. Read more
Source§

fn shared(self) -> Shared<Self>
where Self: Sized, Self::Output: Clone,

Create a cloneable handle to this future where all handles will resolve to the same result. Read more
Source§

fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
where Self: Sized + Send + 'a,

Wrap the future in a Box, pinning it. Read more
Source§

fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>
where Self: Sized + 'a,

Wrap the future in a Box, pinning it. Read more
Source§

fn unit_error(self) -> UnitError<Self>
where Self: Sized,

Source§

fn never_error(self) -> NeverError<Self>
where Self: Sized,

Source§

fn poll_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output>
where Self: Unpin,

A convenience for calling Future::poll on Unpin future types.
Source§

fn now_or_never(self) -> Option<Self::Output>
where Self: Sized,

Evaluates and consumes the future, returning the resulting output if the future is ready after the first call to Future::poll. Read more
Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
Source§

impl<R> ReadableBoxExt for R
where R: Readable<Storage = UnsyncStorage> + ?Sized,

Source§

fn boxed(self) -> ReadSignal<Self::Target>
where Self: Sized + 'static,

Box the readable value into a trait object. This is useful for passing around readable values without knowing their concrete type.
Source§

impl<R> ReadableExt for R
where R: Readable + ?Sized,

Source§

fn read(&self) -> <Self::Storage as AnyStorage>::Ref<'_, Self::Target>
where Self::Target: 'static,

Get the current value of the state. If this is a signal, this will subscribe the current scope to the signal. If the value has been dropped, this will panic. Calling this on a Signal is the same as using the signal() syntax to read and subscribe to its value
Source§

fn try_read( &self, ) -> Result<<Self::Storage as AnyStorage>::Ref<'_, Self::Target>, BorrowError>
where Self::Target: 'static,

Try to get the current value of the state. If this is a signal, this will subscribe the current scope to the signal.
Source§

fn read_unchecked( &self, ) -> <Self::Storage as AnyStorage>::Ref<'static, Self::Target>
where Self::Target: 'static,

Get a reference to the value without checking the lifetime. This will subscribe the current scope to the signal. Read more
Source§

fn peek(&self) -> <Self::Storage as AnyStorage>::Ref<'_, Self::Target>
where Self::Target: 'static,

Get the current value of the state without subscribing to updates. If the value has been dropped, this will panic. Read more
Source§

fn try_peek( &self, ) -> Result<<Self::Storage as AnyStorage>::Ref<'_, Self::Target>, BorrowError>
where Self::Target: 'static,

Try to peek the current value of the signal without subscribing to updates. If the value has been dropped, this will return an error.
Source§

fn peek_unchecked( &self, ) -> <Self::Storage as AnyStorage>::Ref<'static, Self::Target>
where Self::Target: 'static,

Get the current value of the signal without checking the lifetime. Unlike read, this will not subscribe the current scope to the signal which can cause parts of your UI to not update. Read more
Source§

fn map<F, O>(self, f: F) -> MappedSignal<O, Self, F>
where Self: Sized + Clone, F: Fn(&Self::Target) -> &O,

Map the references of the readable value to a new type. This lets you provide a view into the readable value without creating a new signal or cloning the value. Read more
Source§

fn cloned(&self) -> Self::Target
where Self::Target: Clone + 'static,

Clone the inner value and return it. If the value has been dropped, this will panic.
Source§

fn with<O>(&self, f: impl FnOnce(&Self::Target) -> O) -> O
where Self::Target: 'static,

Run a function with a reference to the value. If the value has been dropped, this will panic.
Source§

fn with_peek<O>(&self, f: impl FnOnce(&Self::Target) -> O) -> O
where Self::Target: 'static,

Run a function with a reference to the value. If the value has been dropped, this will panic.
Source§

fn index<I>( &self, index: I, ) -> <Self::Storage as AnyStorage>::Ref<'_, <Self::Target as Index<I>>::Output>
where Self::Target: Index<I> + 'static,

Index into the inner value and return a reference to the result. If the value has been dropped or the index is invalid, this will panic.
Source§

impl<T, R> ReadableOptionExt<T> for R
where R: Readable<Target = Option<T>>,

Source§

fn unwrap(&self) -> T
where T: Clone + 'static,

Unwraps the inner value and clones it.
Source§

fn as_ref(&self) -> Option<<Self::Storage as AnyStorage>::Ref<'_, T>>
where T: 'static,

Attempts to read the inner value of the Option.
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<F> SpawnIfAsync<AsyncMarker> for F
where F: Future<Output = ()> + 'static,

Source§

fn spawn(self)

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WritableBoxedExt for T
where T: Writable<Storage = UnsyncStorage> + 'static,

Source§

fn boxed_mut(self) -> WriteSignal<<T as Readable>::Target>

Box the writable value into a trait object. This is useful for passing around writable values without knowing their concrete type.
Source§

impl<W> WritableExt for W
where W: Writable + ?Sized,

Source§

fn write( &mut self, ) -> WriteLock<'_, Self::Target, Self::Storage, Self::WriteMetadata>
where Self::Target: 'static,

Get a mutable reference to the value. If the value has been dropped, this will panic.
Source§

fn try_write( &mut self, ) -> Result<WriteLock<'_, Self::Target, Self::Storage, Self::WriteMetadata>, BorrowMutError>
where Self::Target: 'static,

Try to get a mutable reference to the value.
Source§

fn write_unchecked( &self, ) -> WriteLock<'static, Self::Target, Self::Storage, Self::WriteMetadata>
where Self::Target: 'static,

Get a mutable reference to the value without checking the lifetime. This will update any subscribers. Read more
Source§

fn map_mut<O, F, FMut>( self, f: F, f_mut: FMut, ) -> MappedMutSignal<O, Self, F, FMut>
where Self: Sized, F: Fn(&Self::Target) -> &O, FMut: Fn(&mut Self::Target) -> &mut O, O: ?Sized,

Map the references and mutable references of the writable value to a new type. This lets you provide a view into the writable value without creating a new signal or cloning the value. Read more
Source§

fn with_mut<O>(&mut self, f: impl FnOnce(&mut Self::Target) -> O) -> O
where Self::Target: 'static,

Run a function with a mutable reference to the value. If the value has been dropped, this will panic.
Source§

fn set(&mut self, value: Self::Target)
where Self::Target: Sized + 'static,

Set the value of the signal. This will trigger an update on all subscribers.
Source§

fn toggle(&mut self)
where Self::Target: Not<Output = Self::Target> + Clone + 'static,

Invert the boolean value of the signal. This will trigger an update on all subscribers.
Source§

fn index_mut<I>( &mut self, index: I, ) -> WriteLock<'_, <Self::Target as Index<I>>::Output, Self::Storage, Self::WriteMetadata>
where Self::Target: IndexMut<I> + 'static,

Index into the inner value and return a reference to the result.
Source§

fn take(&mut self) -> Self::Target
where Self::Target: Default + 'static,

Takes the value out of the Signal, leaving a Default in its place.
Source§

fn replace(&mut self, value: Self::Target) -> Self::Target
where Self::Target: Sized + 'static,

Replace the value in the Signal, returning the old value.
Source§

impl<T, W> WritableOptionExt<T> for W
where W: Writable<Target = Option<T>>,

Source§

fn get_or_insert( &mut self, default: T, ) -> WriteLock<'_, T, Self::Storage, Self::WriteMetadata>
where T: 'static,

Gets the value out of the Option, or inserts the given value if the Option is empty.
Source§

fn get_or_insert_with( &mut self, default: impl FnOnce() -> T, ) -> WriteLock<'_, T, Self::Storage, Self::WriteMetadata>
where T: 'static,

Gets the value out of the Option, or inserts the value returned by the given function if the Option is empty.
Source§

fn as_mut( &mut self, ) -> Option<WriteLock<'_, T, Self::Storage, Self::WriteMetadata>>
where T: 'static,

Attempts to write the inner value of the Option.
Source§

impl<T> DependencyElement for T
where T: 'static + PartialEq + Clone,