Struct sauron::prelude::prelude::Effects

source ·
pub struct Effects<MSG, XMSG> {
    pub local: Vec<Cmd<MSG>>,
    pub external: Vec<Cmd<XMSG>>,
}
Expand description

Effects is a convenient way to group Msg for component to execute subsequent updates based on certain conditions. This can be used for doing animation and incremental changes to the view to provide an effect of transition or animation.

Effects contains 2 types of Messages. The local messages which will be executed in its own component on the next update loop. The other type is the external effects which are Messages that are sent to the parent Component in response to an event that has been triggerred.

Fields§

§local: Vec<Cmd<MSG>>

Messages that will be executed locally in the Component

§external: Vec<Cmd<XMSG>>

effects that will be executed on the parent Component which instantiate this component

Implementations§

source§

impl<MSG, XMSG> Effects<MSG, XMSG>
where MSG: 'static,

source

pub fn new( local: impl IntoIterator<Item = MSG>, external: impl IntoIterator<Item = XMSG> ) -> Effects<MSG, XMSG>
where XMSG: 'static,

create a new Effects with local and external expects respectively

source

pub fn with_local(local: impl IntoIterator<Item = MSG>) -> Effects<MSG, XMSG>

Create an Effects with local messages that will be executed on the next update loop on this Component

source

pub fn with_external( external: impl IntoIterator<Item = XMSG> ) -> Effects<MSG, XMSG>
where XMSG: 'static,

Create an Effects with extern messages that will be executed on the parent Component

source

pub fn none() -> Effects<MSG, XMSG>

Create and empty Effects

source

pub fn map_msg<F, MSG2>(self, f: F) -> Effects<MSG2, XMSG>
where F: Fn(MSG) -> MSG2 + Clone + 'static, MSG2: 'static,

Map the local messages of this Effects such that MSG will be transposed into MSG2 with the use of the mapping function f.

The external messages stays the same.

source

pub fn map_external<F, XMSG2>(self, f: F) -> Effects<MSG, XMSG2>
where F: Fn(XMSG) -> XMSG2 + Clone + 'static, XMSG: 'static, XMSG2: 'static,

Map the external messages of this Effects such that XMSG will be transposed into XMSG2 with the use of the mapping function f

source

pub fn localize<F, XMSG2>(self, f: F) -> Effects<XMSG, XMSG2>
where F: Fn(MSG) -> XMSG + Clone + 'static, XMSG: 'static, XMSG2: 'static,

derives an Effects which contains only local effects by transforming the external messages and mapping them with function f such that they can be of the same type as local effects them merge them together into local effects.

source

pub fn append_local( self, local: impl IntoIterator<Item = MSG> ) -> Effects<MSG, XMSG>

Append this msgs to the local effects

source

pub fn batch( all_effects: impl IntoIterator<Item = Effects<MSG, XMSG>> ) -> Effects<MSG, XMSG>

Merge all the internal objects of this Vec of Effects to produce only one.

source

pub fn extend( self, local: impl IntoIterator<Item = MSG>, external: impl IntoIterator<Item = XMSG> ) -> Effects<MSG, XMSG>
where XMSG: 'static,

Extern the local and external MSG of this Effect

source§

impl<MSG> Effects<MSG, MSG>
where MSG: 'static,

source

pub fn merge(self) -> Effects<MSG, ()>

merge external msg into local msg, if they are of the same type

Trait Implementations§

source§

impl<MSG, XMSG> From<Cmd<MSG>> for Effects<MSG, XMSG>

source§

fn from(task: Cmd<MSG>) -> Effects<MSG, XMSG>

Converts to this type from the input type.
source§

impl<APP> From<Effects<<APP as Application>::MSG, ()>> for Dispatch<APP>
where APP: Application,

source§

fn from(effects: Effects<<APP as Application>::MSG, ()>) -> Dispatch<APP>

Convert Effects that has only follow ups

source§

impl<MSG> From<Effects<MSG, ()>> for Cmd<MSG>
where MSG: 'static,

source§

fn from(effects: Effects<MSG, ()>) -> Cmd<MSG>

Convert Effects that has only follow ups

Auto Trait Implementations§

§

impl<MSG, XMSG> Freeze for Effects<MSG, XMSG>

§

impl<MSG, XMSG> !RefUnwindSafe for Effects<MSG, XMSG>

§

impl<MSG, XMSG> !Send for Effects<MSG, XMSG>

§

impl<MSG, XMSG> !Sync for Effects<MSG, XMSG>

§

impl<MSG, XMSG> Unpin for Effects<MSG, XMSG>

§

impl<MSG, XMSG> !UnwindSafe for Effects<MSG, XMSG>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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 T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.