pub struct Scope<COMP: BaseComponent> { /* private fields */ }
Expand description
A context which allows sending messages to a component.
Implementations§
Source§impl<COMP: BaseComponent> Scope<COMP>
impl<COMP: BaseComponent> Scope<COMP>
Sourcepub fn get_parent(&self) -> Option<&AnyScope>
pub fn get_parent(&self) -> Option<&AnyScope>
Returns the parent scope
Sourcepub fn callback<F, IN, M>(&self, function: F) -> Callback<IN>
pub fn callback<F, IN, M>(&self, function: F) -> Callback<IN>
Creates a Callback
which will send a message to the linked
component’s update method when invoked.
If your callback function returns a Future,
use callback_future
instead.
Sourcepub fn batch_callback<F, IN, OUT>(&self, function: F) -> Callback<IN>where
F: Fn(IN) -> OUT + 'static,
OUT: SendAsMessage<COMP>,
pub fn batch_callback<F, IN, OUT>(&self, function: F) -> Callback<IN>where
F: Fn(IN) -> OUT + 'static,
OUT: SendAsMessage<COMP>,
Creates a Callback
which will send a batch of messages back
to the linked component’s update method when invoked.
The callback function’s return type is generic to allow for dealing with both
Option
and Vec
nicely. Option
can be used when dealing with a callback that
might not need to send an update.
link.batch_callback(|_| vec![Msg::A, Msg::B]);
link.batch_callback(|_| Some(Msg::A));
Sourcepub fn context<T: Clone + PartialEq + 'static>(
&self,
callback: Callback<T>,
) -> Option<(T, ContextHandle<T>)>
pub fn context<T: Clone + PartialEq + 'static>( &self, callback: Callback<T>, ) -> Option<(T, ContextHandle<T>)>
Accesses a value provided by a parent ContextProvider
component of the
same type.
Sourcepub fn send_future<Fut, Msg>(&self, future: Fut)
pub fn send_future<Fut, Msg>(&self, future: Fut)
Sourcepub fn callback_future<F, Fut, IN, Msg>(&self, function: F) -> Callback<IN>
pub fn callback_future<F, Fut, IN, Msg>(&self, function: F) -> Callback<IN>
Sourcepub fn send_future_batch<Fut>(&self, future: Fut)
pub fn send_future_batch<Fut>(&self, future: Fut)
Sourcepub fn send_stream<S, M>(&self, stream: S)
pub fn send_stream<S, M>(&self, stream: S)
This method asynchronously awaits a [Stream
] that returns a series of messages and sends
them to the linked component.
§Panics
If the stream panics, then the promise will not resolve, and will leak.
§Note
This method will not notify the component when the stream has been fully exhausted. If
you want this feature, you can add an EOF message variant for your component and use
[StreamExt::chain
] and stream::once
to chain an EOF message to
the original stream. If your stream is produced by another crate, you can use
[StreamExt::map
] to transform the stream’s item type to the component message type.
Sourcepub fn get_component(&self) -> Option<impl Deref<Target = COMP> + '_>
pub fn get_component(&self) -> Option<impl Deref<Target = COMP> + '_>
Returns the linked component if available
Sourcepub fn send_message<T>(&self, msg: T)
pub fn send_message<T>(&self, msg: T)
Send a message to the component.
Sourcepub fn send_message_batch(&self, messages: Vec<COMP::Message>)
pub fn send_message_batch(&self, messages: Vec<COMP::Message>)
Send a batch of messages to the component.
This is slightly more efficient than calling send_message
in a loop.
Trait Implementations§
Source§impl<COMP: BaseComponent> Clone for Scope<COMP>
impl<COMP: BaseComponent> Clone for Scope<COMP>
Source§impl<COMP: BaseComponent> Debug for Scope<COMP>
impl<COMP: BaseComponent> Debug for Scope<COMP>
Source§impl<Comp: Component> ImplicitClone for Scope<Comp>
impl<Comp: Component> ImplicitClone for Scope<Comp>
§fn implicit_clone(&self) -> Self
fn implicit_clone(&self) -> Self
Auto Trait Implementations§
impl<COMP> Freeze for Scope<COMP>
impl<COMP> !RefUnwindSafe for Scope<COMP>
impl<COMP> !Send for Scope<COMP>
impl<COMP> !Sync for Scope<COMP>
impl<COMP> Unpin for Scope<COMP>where
COMP: Unpin,
impl<COMP> !UnwindSafe for Scope<COMP>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self
to a value of a Properties
struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self
to a value of a Properties
struct.