Struct Global

Source
pub struct Global<T, R = T> { /* private fields */ }
Expand description

A lazy value that is created once per application and can be accessed from anywhere in that application

Implementations§

Source§

impl<T: PartialEq + 'static> Global<Memo<T>, T>

Source

pub fn id(&self) -> GenerationalBoxId

Get the generational id of the signal.

Source

pub fn memo(&self) -> Memo<T>

Resolve the global memo. This will try to get the existing value from the current virtual dom, and if it doesn’t exist, it will create a new one.

Source§

impl<T: 'static> Global<Signal<T>, T>

Source

pub fn id(&self) -> GenerationalBoxId

Get the generational id of the signal.

Source

pub fn signal(&self) -> Signal<T>

Resolve the global signal. This will try to get the existing value from the current virtual dom, and if it doesn’t exist, it will create a new one.

Source§

impl<T, R: 'static> Global<T, R>
where T: Writable<Target = R> + InitializeFromFunction<R> + Clone + 'static,

Source

pub fn write(&self) -> T::Mut<'static, R>

Write this value

Source

pub fn with_mut<O>(&self, f: impl FnOnce(&mut R) -> O) -> O

Run a closure with a mutable reference to the signal’s value. If the signal has been dropped, this will panic.

Source§

impl<T, R> Global<T, R>
where T: InitializeFromFunction<R> + Clone + 'static,

Source

pub const fn new(constructor: fn() -> R) -> Self

Create a new global value

Source

pub const fn with_name(constructor: fn() -> R, key: &'static str) -> Self

Create this global signal with a specific key. This is useful for ensuring that the signal is unique across the application and accessible from outside the application too.

Source

pub const fn with_location( constructor: fn() -> R, file: &'static str, line: u32, column: u32, index: usize, ) -> Self

Create this global signal with a specific key. This is useful for ensuring that the signal is unique across the application and accessible from outside the application too.

Source

pub fn key(&self) -> GlobalKey<'static>

Get the key for this global

Source

pub fn resolve(&self) -> T

Resolve the global value. This will try to get the existing value from the current virtual dom, and if it doesn’t exist, it will create a new one.

Source

pub fn origin_scope(&self) -> ScopeId

Get the scope the signal was created in.

Trait Implementations§

Source§

impl<T, R: Clone + 'static> Deref for Global<T, R>
where T: Readable<Target = R> + InitializeFromFunction<R> + Clone + 'static,

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() -> R

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T, R: 'static> Readable for Global<T, R>
where T: Readable<Target = R> + InitializeFromFunction<R> + Clone + 'static,

Source§

type Target = R

The target type of the reference.
Source§

type Storage = <T as Readable>::Storage

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) -> BorrowResult<ReadableRef<'static, Self>>

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 read(&self) -> ReadableRef<'_, Self>

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<ReadableRef<'_, Self>, BorrowError>

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) -> ReadableRef<'static, Self>

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) -> ReadableRef<'_, Self>

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<ReadableRef<'_, 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.
Source§

fn peek_unchecked(&self) -> ReadableRef<'static, Self>

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 cloned(&self) -> Self::Target
where Self::Target: Clone,

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

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

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, ) -> ReadableRef<'_, Self, <Self::Target as Index<I>>::Output>
where Self::Target: Index<I>,

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: 'static> Writable for Global<T, R>
where T: Writable<Target = R> + InitializeFromFunction<R> + Clone + 'static,

Source§

type Mut<'a, Read: ?Sized + 'static> = <T as Writable>::Mut<'a, Read>

The type of the reference.
Source§

fn map_mut<I: ?Sized, U: ?Sized + 'static, F: FnOnce(&mut I) -> &mut U>( ref_: Self::Mut<'_, I>, f: F, ) -> Self::Mut<'_, U>

Map the reference to a new type.
Source§

fn try_map_mut<I: ?Sized + 'static, U: ?Sized + 'static, F: FnOnce(&mut I) -> Option<&mut U>>( ref_: Self::Mut<'_, I>, f: F, ) -> Option<Self::Mut<'_, U>>

Try to map the reference to a new type.
Source§

fn downcast_lifetime_mut<'a: 'b, 'b, Read: ?Sized + 'static>( mut_: Self::Mut<'a, Read>, ) -> Self::Mut<'b, Read>

Downcast a mutable reference in a RefMut to a more specific lifetime Read more
Source§

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

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

fn write(&mut self) -> WritableRef<'_, Self>

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

fn try_write(&mut self) -> Result<WritableRef<'_, Self>, BorrowMutError>

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

fn write_unchecked(&self) -> WritableRef<'static, Self>

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

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

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,

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,

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

fn index_mut<I>( &mut self, index: I, ) -> WritableRef<'_, Self, <Self::Target as Index<I>>::Output>
where Self::Target: IndexMut<I>,

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

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

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,

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

Auto Trait Implementations§

§

impl<T, R> Freeze for Global<T, R>

§

impl<T, R> RefUnwindSafe for Global<T, R>

§

impl<T, R> Send for Global<T, R>

§

impl<T, R> Sync for Global<T, R>

§

impl<T, R> Unpin for Global<T, R>

§

impl<T, R> UnwindSafe for Global<T, R>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<T, R> ReadableOptionExt<T> for R
where T: 'static, R: Readable<Target = Option<T>>,

Source§

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

Unwraps the inner value and clones it.
Source§

fn as_ref(&self) -> Option<ReadableRef<'_, Self, T>>

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

impl<T, E, R> ReadableResultExt<T, E> for R
where T: 'static, E: 'static, R: Readable<Target = Result<T, E>>,

Source§

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

Unwraps the inner value and clones it.
Source§

fn as_ref(&self) -> Result<ReadableRef<'_, Self, T>, ReadableRef<'_, Self, E>>

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

impl<T, R> ReadableVecExt<T> for R
where T: 'static, R: Readable<Target = Vec<T>>,

Source§

fn len(&self) -> usize

Returns the length of the inner vector.
Source§

fn is_empty(&self) -> bool

Returns true if the inner vector is empty.
Source§

fn first(&self) -> Option<ReadableRef<'_, Self, T>>

Get the first element of the inner vector.
Source§

fn last(&self) -> Option<ReadableRef<'_, Self, T>>

Get the last element of the inner vector.
Source§

fn get(&self, index: usize) -> Option<ReadableRef<'_, Self, T>>

Get the element at the given index of the inner vector.
Source§

fn iter(&self) -> ReadableValueIterator<'_, Self>
where Self: Sized,

Get an iterator over the values of the inner vector.
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<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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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, W> WritableOptionExt<T> for W
where T: 'static, W: Writable<Target = Option<T>>,

Source§

fn get_or_insert(&mut self, default: T) -> WritableRef<'_, Self, T>

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, ) -> WritableRef<'_, Self, T>

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<WritableRef<'_, Self, T>>

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

impl<T, W> WritableVecExt<T> for W
where T: 'static, W: Writable<Target = Vec<T>>,

Source§

fn push(&mut self, value: T)

Pushes a new value to the end of the vector.
Source§

fn pop(&mut self) -> Option<T>

Pops the last value from the vector.
Source§

fn insert(&mut self, index: usize, value: T)

Inserts a new value at the given index.
Source§

fn remove(&mut self, index: usize) -> T

Removes the value at the given index.
Source§

fn clear(&mut self)

Clears the vector, removing all values.
Source§

fn extend(&mut self, iter: impl IntoIterator<Item = T>)

Extends the vector with the given iterator.
Source§

fn truncate(&mut self, len: usize)

Truncates the vector to the given length.
Source§

fn swap_remove(&mut self, index: usize) -> T

Swaps two values in the vector.
Source§

fn retain(&mut self, f: impl FnMut(&T) -> bool)

Retains only the values that match the given predicate.
Source§

fn split_off(&mut self, at: usize) -> Vec<T>

Splits the vector into two at the given index.
Source§

fn get_mut(&mut self, index: usize) -> Option<WritableRef<'_, Self, T>>

Try to mutably get an element from the vector.
Source§

fn iter_mut(&mut self) -> WritableValueIterator<'_, Self>
where Self: Sized + Clone,

Gets an iterator over the values of the vector.