Struct relm4::MicroComponent
source · pub struct MicroComponent<Model: MicroModel> { /* private fields */ }
Expand description
MicroComponent is a small component that lives in their parents model, can be modified from their parents model but at the same time have their own widgets and update function
Implementations§
source§impl<Model> MicroComponent<Model>where
Model::Widgets: MicroWidgets<Model> + 'static,
Model::Msg: 'static,
Model::Data: 'static,
Model: MicroModel + 'static,
impl<Model> MicroComponent<Model>where Model::Widgets: MicroWidgets<Model> + 'static, Model::Msg: 'static, Model::Data: 'static, Model: MicroModel + 'static,
sourcepub fn new(model: Model, data: Model::Data) -> Self
pub fn new(model: Model, data: Model::Data) -> Self
Creates new MicroComponent
sourcepub fn update_view(&self) -> Result<(), MicroComponentError>
pub fn update_view(&self) -> Result<(), MicroComponentError>
Updates a view of this MicroComponent
sourcepub fn model(&self) -> Result<Ref<'_, Model>, BorrowError>
pub fn model(&self) -> Result<Ref<'_, Model>, BorrowError>
Returns model for this MicroComponent
Use this carefully and make sure reference is dropped. It’s using RefCell
internally.
sourcepub fn model_mut(&self) -> Result<RefMut<'_, Model>, BorrowMutError>
pub fn model_mut(&self) -> Result<RefMut<'_, Model>, BorrowMutError>
Returns mutable reference to model for this MicroComponent
Use this carefully and make sure reference is dropped. It’s using RefCell
internally.
If you don’t drop the reference any call to MicroComponent::update_view
will fail.
sourcepub fn widgets(&self) -> Result<RefMut<'_, Model::Widgets>, BorrowMutError>
pub fn widgets(&self) -> Result<RefMut<'_, Model::Widgets>, BorrowMutError>
Returns a mutable reference to the widgets of this MicroComponent
or will fail
when you already have a reference to the widgets
Use this carefully and make sure the reference to the widgets is dropped after use because
otherwise the view function can’t be called as long you own the widgets (it uses RefCell
internally).
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 MicroComponent
.
This can be used by the parent to send messages to this.
sourcepub fn sender(&self) -> Sender<Model::Msg>
pub fn sender(&self) -> Sender<Model::Msg>
Get a sender to send messages to this MicroComponent
.
sourcepub fn root_widget(&self) -> &<Model::Widgets as MicroWidgets<Model>>::Root
pub fn root_widget(&self) -> &<Model::Widgets as MicroWidgets<Model>>::Root
Returns the root widget of this component’s widgets.
source§impl<Model> MicroComponent<Model>where
Model::Widgets: MicroWidgets<Model> + 'static,
Model::Msg: 'static,
Model::Data: 'static,
Model: MicroModel + 'static,
<Model::Widgets as MicroWidgets<Model>>::Root: IsA<Widget>,
impl<Model> MicroComponent<Model>where Model::Widgets: MicroWidgets<Model> + 'static, Model::Msg: 'static, Model::Data: 'static, Model: MicroModel + 'static, <Model::Widgets as MicroWidgets<Model>>::Root: IsA<Widget>,
sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Returns true
of the root widget is connected to a parent widget.