pub struct ScopeId(pub usize);
Expand description
A component’s unique identifier.
ScopeId
is a usize
that acts a key for the internal slab of Scopes. This means that the key is not unique across
time. We do try and guarantee that between calls to wait_for_work
, no ScopeIds will be recycled in order to give
time for any logic that relies on these IDs to properly update.
Tuple Fields§
§0: usize
Implementations§
§impl ScopeId
impl ScopeId
pub fn owner<S>(self) -> Owner<S>where
S: AnyStorage,
pub fn owner<S>(self) -> Owner<S>where
S: AnyStorage,
Get the owner for the current scope.
§impl ScopeId
impl ScopeId
pub fn current_scope_id(self) -> Result<ScopeId, RuntimeError>
pub fn current_scope_id(self) -> Result<ScopeId, RuntimeError>
Get the current scope id
pub fn consume_context<T>(self) -> Option<T>where
T: 'static + Clone,
pub fn consume_context<T>(self) -> Option<T>where
T: 'static + Clone,
Consume context from the current scope
pub fn consume_context_from_scope<T>(self, scope_id: ScopeId) -> Option<T>where
T: 'static + Clone,
pub fn consume_context_from_scope<T>(self, scope_id: ScopeId) -> Option<T>where
T: 'static + Clone,
Consume context from the current scope
pub fn has_context<T>(self) -> Option<T>where
T: 'static + Clone,
pub fn has_context<T>(self) -> Option<T>where
T: 'static + Clone,
Check if the current scope has a context
pub fn provide_context<T>(self, value: T) -> Twhere
T: 'static + Clone,
pub fn provide_context<T>(self, value: T) -> Twhere
T: 'static + Clone,
Provide context to the current scope
pub fn push_future(
self,
fut: impl Future<Output = ()> + 'static
) -> Option<Task>
pub fn push_future( self, fut: impl Future<Output = ()> + 'static ) -> Option<Task>
Pushes the future onto the poll queue to be polled after the component renders.
pub fn spawn(self, fut: impl Future<Output = ()> + 'static)
pub fn spawn(self, fut: impl Future<Output = ()> + 'static)
Spawns the future but does not return the Task
pub fn generation(self) -> Option<usize>
pub fn generation(self) -> Option<usize>
Get the current render since the inception of this component
This can be used as a helpful diagnostic when debugging hooks/renders, etc
pub fn parent_scope(self) -> Option<ScopeId>
pub fn parent_scope(self) -> Option<ScopeId>
Get the parent of the current scope if it exists
pub fn is_descendant_of(self, other: ScopeId) -> bool
pub fn is_descendant_of(self, other: ScopeId) -> bool
Check if the current scope is a descendant of the given scope
pub fn needs_update(self)
pub fn needs_update(self)
Mark the current scope as dirty, causing it to re-render
pub fn schedule_update(&self) -> Arc<dyn Fn() + Sync + Send>
pub fn schedule_update(&self) -> Arc<dyn Fn() + Sync + Send>
Create a subscription that schedules a future render for the reference component. Unlike Self::needs_update
, this function will work outside of the dioxus runtime.
§Notice: you should prefer using crate::prelude::schedule_update_any
pub fn in_runtime<T>(self, f: impl FnOnce() -> T) -> T
pub fn in_runtime<T>(self, f: impl FnOnce() -> T) -> T
Run a closure inside of scope’s runtime
pub fn throw_error(self, error: impl Into<CapturedError> + 'static)
pub fn throw_error(self, error: impl Into<CapturedError> + 'static)
Throw a [CapturedError
] into a scope. The error will bubble up to the nearest [ErrorBoundary
] or the root of the app.
§Examples
fn Component() -> Element {
let request = spawn(async move {
match reqwest::get("https://api.example.com").await {
Ok(_) => todo!(),
// You can explicitly throw an error into a scope with throw_error
Err(err) => ScopeId::APP.throw_error(err)
}
});
todo!()
}
§impl ScopeId
impl ScopeId
pub const APP: ScopeId = _
pub const APP: ScopeId = _
The ScopeId of the main scope passed into [VirtualDom::new
].
This scope will last for the entire duration of your app, making it convenient for long-lived state that is created dynamically somewhere down the component tree.
§Example
use dioxus::prelude::*;
let my_persistent_state = Signal::new_in_scope(String::new(), ScopeId::APP);
pub const ROOT: ScopeId = _
pub const ROOT: ScopeId = _
The ScopeId of the topmost scope in the tree.
This will be higher up in the tree than ScopeId::APP
because dioxus inserts a default [SuspenseBoundary
] and [ErrorBoundary
] at the root of the tree.
Trait Implementations§
§impl<'de> Deserialize<'de> for ScopeId
impl<'de> Deserialize<'de> for ScopeId
§fn deserialize<__D>(
__deserializer: __D
) -> Result<ScopeId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<ScopeId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl Ord for ScopeId
impl Ord for ScopeId
§impl PartialOrd for ScopeId
impl PartialOrd for ScopeId
§fn partial_cmp(&self, other: &ScopeId) -> Option<Ordering>
fn partial_cmp(&self, other: &ScopeId) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more§impl Serialize for ScopeId
impl Serialize for ScopeId
§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for ScopeId
impl Eq for ScopeId
impl StructuralPartialEq for ScopeId
Auto Trait Implementations§
impl Freeze for ScopeId
impl RefUnwindSafe for ScopeId
impl Send for ScopeId
impl Sync for ScopeId
impl Unpin for ScopeId
impl UnwindSafe for ScopeId
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
§impl<T> CallHasher for T
impl<T> CallHasher for T
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more