Struct relm4::AsyncRelmWorker
source · [−]pub struct AsyncRelmWorker<Model, ParentModel> where
Model: AsyncComponentUpdate<ParentModel, Widgets = ()> + Send + 'static,
Model::Components: Send,
ParentModel: ModelTrait,
ParentModel::Msg: Send,
Model::Msg: Send, { /* private fields */ }
This is supported on crate feature
tokio-rt
only.Expand description
A AsyncRelmWorker
is like a RelmWorker
but runs the AsyncComponentUpdate::update
function in
a tokio Runtime
.
Implementations
sourceimpl<Model, ParentModel> AsyncRelmWorker<Model, ParentModel> where
Model: AsyncComponentUpdate<ParentModel, Widgets = ()> + Send,
Model::Components: Send,
ParentModel: ModelTrait,
ParentModel::Msg: Send,
Model::Msg: Send,
impl<Model, ParentModel> AsyncRelmWorker<Model, ParentModel> where
Model: AsyncComponentUpdate<ParentModel, Widgets = ()> + Send,
Model::Components: Send,
ParentModel: ModelTrait,
ParentModel::Msg: Send,
Model::Msg: Send,
sourcepub fn with_new_tokio_rt(
parent_model: &ParentModel,
parent_sender: Sender<ParentModel::Msg>
) -> Self
pub fn with_new_tokio_rt(
parent_model: &ParentModel,
parent_sender: Sender<ParentModel::Msg>
) -> Self
Create a new AsyncRelmWorker
that runs the AsyncComponentUpdate::update
function in
a tokio Runtime
.
sourcepub fn send(&self, msg: Model::Msg) -> Result<(), SendError<Model::Msg>>
pub fn send(&self, msg: Model::Msg) -> Result<(), SendError<Model::Msg>>
Send a message to this component. This can be used by the parent to send messages to this worker.
Examples found in repository
relm4-examples/examples/tokio.rs (line 101)
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
fn update(&mut self, msg: AppMsg, components: &AppComponents, _sender: Sender<AppMsg>) -> bool {
self.reset();
match msg {
AppMsg::Request(url) => {
components.http.send(HttpMsg::Request(url)).unwrap();
self.set_text_waiting(true);
self.set_image_waiting(true);
}
AppMsg::SetText(text_opt) => {
self.set_text_waiting(false);
if let Some(text) = text_opt {
self.set_text(text);
} else {
self.set_text("No response".to_string());
}
}
AppMsg::SetImage(bytes_opt) => {
self.set_image_waiting(false);
if let Some(bytes) = bytes_opt {
let buf = Pixbuf::from_read(bytes.reader()).ok();
self.set_image_data(buf);
} else {
self.set_image_data(None);
}
}
}
true
}
Trait Implementations
sourceimpl<Model: Clone, ParentModel: Clone> Clone for AsyncRelmWorker<Model, ParentModel> where
Model: AsyncComponentUpdate<ParentModel, Widgets = ()> + Send + 'static,
Model::Components: Send,
ParentModel: ModelTrait,
ParentModel::Msg: Send,
Model::Msg: Send,
Model::Msg: Clone,
impl<Model: Clone, ParentModel: Clone> Clone for AsyncRelmWorker<Model, ParentModel> where
Model: AsyncComponentUpdate<ParentModel, Widgets = ()> + Send + 'static,
Model::Components: Send,
ParentModel: ModelTrait,
ParentModel::Msg: Send,
Model::Msg: Send,
Model::Msg: Clone,
sourcefn clone(&self) -> AsyncRelmWorker<Model, ParentModel>
fn clone(&self) -> AsyncRelmWorker<Model, ParentModel>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<Model: Debug, ParentModel: Debug> Debug for AsyncRelmWorker<Model, ParentModel> where
Model: AsyncComponentUpdate<ParentModel, Widgets = ()> + Send + 'static,
Model::Components: Send,
ParentModel: ModelTrait,
ParentModel::Msg: Send,
Model::Msg: Send,
Model::Msg: Debug,
impl<Model: Debug, ParentModel: Debug> Debug for AsyncRelmWorker<Model, ParentModel> where
Model: AsyncComponentUpdate<ParentModel, Widgets = ()> + Send + 'static,
Model::Components: Send,
ParentModel: ModelTrait,
ParentModel::Msg: Send,
Model::Msg: Send,
Model::Msg: Debug,
Auto Trait Implementations
impl<Model, ParentModel> RefUnwindSafe for AsyncRelmWorker<Model, ParentModel> where
Model: RefUnwindSafe,
ParentModel: RefUnwindSafe,
impl<Model, ParentModel> Send for AsyncRelmWorker<Model, ParentModel> where
ParentModel: Send,
impl<Model, ParentModel> Sync for AsyncRelmWorker<Model, ParentModel> where
Model: Sync,
ParentModel: Sync,
impl<Model, ParentModel> Unpin for AsyncRelmWorker<Model, ParentModel> where
Model: Unpin,
ParentModel: Unpin,
impl<Model, ParentModel> UnwindSafe for AsyncRelmWorker<Model, ParentModel> where
Model: UnwindSafe,
ParentModel: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more