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,

source

pub fn new(model: Model, data: Model::Data) -> Self

Creates new MicroComponent

source

pub fn update_view(&self) -> Result<(), MicroComponentError>

Updates a view of this MicroComponent

source

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.

source

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.

source

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

source

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.

source

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

Get a sender to send messages to this MicroComponent.

source

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>,

source

pub fn is_connected(&self) -> bool

Returns true of the root widget is connected to a parent widget.

source

pub fn try_diconnect_root(&self) -> bool

Tries to disconnect the root widget from its parent widget.

Returns true of the root widget was disconnected from the parent widget and false if nothing was done.

Trait Implementations§

source§

impl<Model: Debug + MicroModel> Debug for MicroComponent<Model>where Model::Widgets: 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> !RefUnwindSafe for MicroComponent<Model>

§

impl<Model> !Send for MicroComponent<Model>

§

impl<Model> !Sync for MicroComponent<Model>

§

impl<Model> Unpin for MicroComponent<Model>where <<Model as MicroModel>::Widgets as MicroWidgets<Model>>::Root: Unpin,

§

impl<Model> !UnwindSafe for MicroComponent<Model>

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.