Struct relm4::RelmComponent

source ·
pub struct RelmComponent<Model, ParentModel>where
    Model: ComponentUpdate<ParentModel> + 'static,
    ParentModel: ModelTrait,
    Model::Widgets: WidgetsTrait<Model, ParentModel> + 'static,{ /* private fields */ }
Expand description

A component that can be part of the main application or other components.

A RelmComponent has its own widget, model and message type and can send messages to its parent and its children components.

Multiple RelmComponents that have the same parent are usually bundled in a struct that implements Components.

Implementations§

source§

impl<Model, ParentModel> RelmComponent<Model, ParentModel>where Model::Widgets: WidgetsTrait<Model, ParentModel> + 'static, ParentModel: ModelTrait, Model: ComponentUpdate<ParentModel> + 'static,

source

pub fn new( parent_model: &ParentModel, parent_sender: Sender<ParentModel::Msg> ) -> Self

Create a new RelmComponent.

source

pub fn connect_parent(&mut self, parent_widgets: &ParentModel::Widgets)

Connect the widgets to the widgets of the parent widget.

source

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 component.

source

pub fn sender(&self) -> Sender<Model::Msg>

Get a sender to send messages to this component.

source

pub fn root_widget( &self ) -> &<Model::Widgets as WidgetsTrait<Model, ParentModel>>::Root

Returns the root widget of this component’s widgets. Can be used by the parent to connect the root widget to the parent’s widgets.

source

pub fn widgets(&self) -> Option<RefMut<'_, Model::Widgets>>

Returns a mutable reference to the widgets of this component or None if 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).

Trait Implementations§

source§

impl<Model, ParentModel> Debug for RelmComponent<Model, ParentModel>where Model: ComponentUpdate<ParentModel> + 'static + Debug, ParentModel: ModelTrait + Debug, Model::Widgets: WidgetsTrait<Model, ParentModel> + 'static + Debug, Model::Components: Debug, Model::Msg: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Model, ParentModel> !RefUnwindSafe for RelmComponent<Model, ParentModel>

§

impl<Model, ParentModel> !Send for RelmComponent<Model, ParentModel>

§

impl<Model, ParentModel> !Sync for RelmComponent<Model, ParentModel>

§

impl<Model, ParentModel> Unpin for RelmComponent<Model, ParentModel>where Model: Unpin, ParentModel: Unpin, <<Model as Model>::Widgets as Widgets<Model, ParentModel>>::Root: Unpin,

§

impl<Model, ParentModel> !UnwindSafe for RelmComponent<Model, ParentModel>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.