[][src]Trait reducer::Reducer

pub trait Reducer<A> {
    fn reduce(&mut self, action: A);
}

Trait for types that represent the logical state of an application.

Perhaps a more accurate mental model for types that implement this trait is that of a state machine, where the nodes correspond to the universe of all possible representable values and the edges correspond to actions.

Required methods

fn reduce(&mut self, action: A)

Implements the transition given the current state and an action.

This method is expected to have no side effects and must never fail. In many cases, an effective way to handle illegal state transitions is to make them idempotent, that is to leave the state unchanged.

Example

use reducer::Reducer;

#[derive(Debug)]
struct Todos(Vec<String>);

// Actions
struct Create(String);
struct Remove(usize);

impl Reducer<Create> for Todos {
    fn reduce(&mut self, Create(todo): Create) {
        self.0.push(todo);
    }
}

impl Reducer<Remove> for Todos {
    fn reduce(&mut self, Remove(i): Remove) {
        if i < self.0.len() {
            self.0.remove(i);
        } else {
            // Illegal transition, leave the state unchanged.
        }
    }
}

let mut todos = Todos(vec![]);

todos.reduce(Create("Buy milk".to_string()));
println!("{:?}", todos); // ["Buy milk"]

todos.reduce(Create("Learn Reducer".to_string()));
println!("{:?}", todos); // ["Buy milk", "Learn Reducer"]

todos.reduce(Remove(42)); // out of bounds
println!("{:?}", todos); // ["Buy milk", "Learn Reducer"]

todos.reduce(Remove(0));
println!("{:?}", todos); // ["Learn Reducer"]
Loading content...

Implementations on Foreign Types

impl<A, T: ?Sized> Reducer<A> for Arc<T> where
    T: Reducer<A> + Clone
[src]

Enhances a potentially unsized Reducer with copy-on-write semantics (requires std).

Helps avoiding cloning the entire state when it needs to be sent to other threads, e.g to the rendering thread of a GUI.

Example

use reducer::*;
use std::sync::Arc;

#[derive(Clone)]
struct State { /* ... */ }
struct Action { /* ... */ }

impl Reducer<Action> for State {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

let (tx, mut rx) = futures::channel::mpsc::channel(10);

let state = Arc::new(State { /* ... */ });
let reactor = Reactor::<Error = _>::from_sink(tx);

let mut store = Store::new(state, reactor);

store.dispatch(Action { /* ... */ }); // State is not cloned.

// The channel now holds a reference to the current state.

store.dispatch(Action { /* ... */ }); // State is cloned.

// Drain the channel so that it doesn't hold any references to the current state.
while let Ok(Some(s)) = rx.try_next() {
    // Consume `s`.
}

store.dispatch(Action { /* ... */ }); // State is not cloned.

impl<A, T> Reducer<A> for [T; 0] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 1] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 2] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 3] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 4] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 5] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 6] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 7] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 8] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 9] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 10] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 11] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 12] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 13] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 14] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 15] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 16] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 17] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 18] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 19] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 20] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 21] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 22] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 23] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 24] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 25] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 26] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 27] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 28] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 29] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 30] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 31] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T> Reducer<A> for [T; 32] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the array in order.

Currently implemented for arrays of up to 32 elements.

impl<A, T: ?Sized> Reducer<A> for Box<T> where
    T: Reducer<A>, 
[src]

Updates the potentially unsized nested Reducer (requires std).

impl<A, T: ?Sized> Reducer<A> for Rc<T> where
    T: Reducer<A> + Clone
[src]

Enhances a potentially unsized Reducer with copy-on-write semantics (requires std).

Helps avoiding cloning the entire state when it needs to be sent to other parts of the application.

Example

use reducer::*;
use std::rc::Rc;

#[derive(Clone)]
struct State { /* ... */ }
struct Action { /* ... */ }

impl Reducer<Action> for State {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

let state = Rc::new(State { /* ... */ });
let reactor = Reactor::<Error = _>::from_sink(vec![]);

let mut store = Store::new(state, reactor);

store.dispatch(Action { /* ... */ }); // State is not cloned.

// The reactor now holds a reference to the current state.

store.dispatch(Action { /* ... */ }); // State is cloned.

// Replace the reactor by an empty one.
let mut reactor = store.subscribe(Reactor::<Error = _>::from_sink(vec![]));

// Consume all references to the state.
while let Some(s) = reactor.pop() {
    // Consume `s`.
}

store.dispatch(Action { /* ... */ }); // State is not cloned.

impl<'a, A, T: ?Sized> Reducer<A> for &'a mut T where
    T: Reducer<A>, 
[src]

Forwards the event to a potentially stack allocated Reducer.

impl<A, T> Reducer<A> for [T] where
    A: Clone,
    T: Reducer<A>, 
[src]

Updates all Reducers in the slice in order.

impl<A, B> Reducer<A> for (B,) where
    A: Clone,
    B: Reducer<A>, 
[src]

Updates all Reducers in the tuple in order.

Currently implemented for tuples of up to 12 elements.

Example

use reducer::Reducer;

struct ProductDetails { /* ... */ }
struct ShoppingCart { /* ... */ }
struct UserProfile { /* ... */ }

#[derive(Clone)]
enum Action {
    ViewProduct(/* ... */),
    AddToShoppingCart(/* ... */),
    UpdatePaymentPreferences(/* ... */),
    // ...
};

impl Reducer<Action> for ProductDetails {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for ShoppingCart {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for UserProfile {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

let product = ProductDetails { /* ... */ };
let cart = ShoppingCart { /* ... */ };
let user = UserProfile { /* ... */ };

let mut shop = (product, cart, user);

// `shop` itself implements Reducer<Action>
shop.reduce(Action::AddToShoppingCart( /* ... */ ));

impl<A, B, C> Reducer<A> for (B, C) where
    A: Clone,
    B: Reducer<A>,
    C: Reducer<A>, 
[src]

Updates all Reducers in the tuple in order.

Currently implemented for tuples of up to 12 elements.

Example

use reducer::Reducer;

struct ProductDetails { /* ... */ }
struct ShoppingCart { /* ... */ }
struct UserProfile { /* ... */ }

#[derive(Clone)]
enum Action {
    ViewProduct(/* ... */),
    AddToShoppingCart(/* ... */),
    UpdatePaymentPreferences(/* ... */),
    // ...
};

impl Reducer<Action> for ProductDetails {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for ShoppingCart {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for UserProfile {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

let product = ProductDetails { /* ... */ };
let cart = ShoppingCart { /* ... */ };
let user = UserProfile { /* ... */ };

let mut shop = (product, cart, user);

// `shop` itself implements Reducer<Action>
shop.reduce(Action::AddToShoppingCart( /* ... */ ));

impl<A, B, C, D> Reducer<A> for (B, C, D) where
    A: Clone,
    B: Reducer<A>,
    C: Reducer<A>,
    D: Reducer<A>, 
[src]

Updates all Reducers in the tuple in order.

Currently implemented for tuples of up to 12 elements.

Example

use reducer::Reducer;

struct ProductDetails { /* ... */ }
struct ShoppingCart { /* ... */ }
struct UserProfile { /* ... */ }

#[derive(Clone)]
enum Action {
    ViewProduct(/* ... */),
    AddToShoppingCart(/* ... */),
    UpdatePaymentPreferences(/* ... */),
    // ...
};

impl Reducer<Action> for ProductDetails {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for ShoppingCart {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for UserProfile {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

let product = ProductDetails { /* ... */ };
let cart = ShoppingCart { /* ... */ };
let user = UserProfile { /* ... */ };

let mut shop = (product, cart, user);

// `shop` itself implements Reducer<Action>
shop.reduce(Action::AddToShoppingCart( /* ... */ ));

impl<A, B, C, D, E> Reducer<A> for (B, C, D, E) where
    A: Clone,
    B: Reducer<A>,
    C: Reducer<A>,
    D: Reducer<A>,
    E: Reducer<A>, 
[src]

Updates all Reducers in the tuple in order.

Currently implemented for tuples of up to 12 elements.

Example

use reducer::Reducer;

struct ProductDetails { /* ... */ }
struct ShoppingCart { /* ... */ }
struct UserProfile { /* ... */ }

#[derive(Clone)]
enum Action {
    ViewProduct(/* ... */),
    AddToShoppingCart(/* ... */),
    UpdatePaymentPreferences(/* ... */),
    // ...
};

impl Reducer<Action> for ProductDetails {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for ShoppingCart {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for UserProfile {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

let product = ProductDetails { /* ... */ };
let cart = ShoppingCart { /* ... */ };
let user = UserProfile { /* ... */ };

let mut shop = (product, cart, user);

// `shop` itself implements Reducer<Action>
shop.reduce(Action::AddToShoppingCart( /* ... */ ));

impl<A, B, C, D, E, F> Reducer<A> for (B, C, D, E, F) where
    A: Clone,
    B: Reducer<A>,
    C: Reducer<A>,
    D: Reducer<A>,
    E: Reducer<A>,
    F: Reducer<A>, 
[src]

Updates all Reducers in the tuple in order.

Currently implemented for tuples of up to 12 elements.

Example

use reducer::Reducer;

struct ProductDetails { /* ... */ }
struct ShoppingCart { /* ... */ }
struct UserProfile { /* ... */ }

#[derive(Clone)]
enum Action {
    ViewProduct(/* ... */),
    AddToShoppingCart(/* ... */),
    UpdatePaymentPreferences(/* ... */),
    // ...
};

impl Reducer<Action> for ProductDetails {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for ShoppingCart {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for UserProfile {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

let product = ProductDetails { /* ... */ };
let cart = ShoppingCart { /* ... */ };
let user = UserProfile { /* ... */ };

let mut shop = (product, cart, user);

// `shop` itself implements Reducer<Action>
shop.reduce(Action::AddToShoppingCart( /* ... */ ));

impl<A, B, C, D, E, F, G> Reducer<A> for (B, C, D, E, F, G) where
    A: Clone,
    B: Reducer<A>,
    C: Reducer<A>,
    D: Reducer<A>,
    E: Reducer<A>,
    F: Reducer<A>,
    G: Reducer<A>, 
[src]

Updates all Reducers in the tuple in order.

Currently implemented for tuples of up to 12 elements.

Example

use reducer::Reducer;

struct ProductDetails { /* ... */ }
struct ShoppingCart { /* ... */ }
struct UserProfile { /* ... */ }

#[derive(Clone)]
enum Action {
    ViewProduct(/* ... */),
    AddToShoppingCart(/* ... */),
    UpdatePaymentPreferences(/* ... */),
    // ...
};

impl Reducer<Action> for ProductDetails {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for ShoppingCart {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for UserProfile {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

let product = ProductDetails { /* ... */ };
let cart = ShoppingCart { /* ... */ };
let user = UserProfile { /* ... */ };

let mut shop = (product, cart, user);

// `shop` itself implements Reducer<Action>
shop.reduce(Action::AddToShoppingCart( /* ... */ ));

impl<A, B, C, D, E, F, G, H> Reducer<A> for (B, C, D, E, F, G, H) where
    A: Clone,
    B: Reducer<A>,
    C: Reducer<A>,
    D: Reducer<A>,
    E: Reducer<A>,
    F: Reducer<A>,
    G: Reducer<A>,
    H: Reducer<A>, 
[src]

Updates all Reducers in the tuple in order.

Currently implemented for tuples of up to 12 elements.

Example

use reducer::Reducer;

struct ProductDetails { /* ... */ }
struct ShoppingCart { /* ... */ }
struct UserProfile { /* ... */ }

#[derive(Clone)]
enum Action {
    ViewProduct(/* ... */),
    AddToShoppingCart(/* ... */),
    UpdatePaymentPreferences(/* ... */),
    // ...
};

impl Reducer<Action> for ProductDetails {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for ShoppingCart {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for UserProfile {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

let product = ProductDetails { /* ... */ };
let cart = ShoppingCart { /* ... */ };
let user = UserProfile { /* ... */ };

let mut shop = (product, cart, user);

// `shop` itself implements Reducer<Action>
shop.reduce(Action::AddToShoppingCart( /* ... */ ));

impl<A, B, C, D, E, F, G, H, I> Reducer<A> for (B, C, D, E, F, G, H, I) where
    A: Clone,
    B: Reducer<A>,
    C: Reducer<A>,
    D: Reducer<A>,
    E: Reducer<A>,
    F: Reducer<A>,
    G: Reducer<A>,
    H: Reducer<A>,
    I: Reducer<A>, 
[src]

Updates all Reducers in the tuple in order.

Currently implemented for tuples of up to 12 elements.

Example

use reducer::Reducer;

struct ProductDetails { /* ... */ }
struct ShoppingCart { /* ... */ }
struct UserProfile { /* ... */ }

#[derive(Clone)]
enum Action {
    ViewProduct(/* ... */),
    AddToShoppingCart(/* ... */),
    UpdatePaymentPreferences(/* ... */),
    // ...
};

impl Reducer<Action> for ProductDetails {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for ShoppingCart {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for UserProfile {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

let product = ProductDetails { /* ... */ };
let cart = ShoppingCart { /* ... */ };
let user = UserProfile { /* ... */ };

let mut shop = (product, cart, user);

// `shop` itself implements Reducer<Action>
shop.reduce(Action::AddToShoppingCart( /* ... */ ));

impl<A, B, C, D, E, F, G, H, I, J> Reducer<A> for (B, C, D, E, F, G, H, I, J) where
    A: Clone,
    B: Reducer<A>,
    C: Reducer<A>,
    D: Reducer<A>,
    E: Reducer<A>,
    F: Reducer<A>,
    G: Reducer<A>,
    H: Reducer<A>,
    I: Reducer<A>,
    J: Reducer<A>, 
[src]

Updates all Reducers in the tuple in order.

Currently implemented for tuples of up to 12 elements.

Example

use reducer::Reducer;

struct ProductDetails { /* ... */ }
struct ShoppingCart { /* ... */ }
struct UserProfile { /* ... */ }

#[derive(Clone)]
enum Action {
    ViewProduct(/* ... */),
    AddToShoppingCart(/* ... */),
    UpdatePaymentPreferences(/* ... */),
    // ...
};

impl Reducer<Action> for ProductDetails {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for ShoppingCart {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for UserProfile {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

let product = ProductDetails { /* ... */ };
let cart = ShoppingCart { /* ... */ };
let user = UserProfile { /* ... */ };

let mut shop = (product, cart, user);

// `shop` itself implements Reducer<Action>
shop.reduce(Action::AddToShoppingCart( /* ... */ ));

impl<A, B, C, D, E, F, G, H, I, J, K> Reducer<A> for (B, C, D, E, F, G, H, I, J, K) where
    A: Clone,
    B: Reducer<A>,
    C: Reducer<A>,
    D: Reducer<A>,
    E: Reducer<A>,
    F: Reducer<A>,
    G: Reducer<A>,
    H: Reducer<A>,
    I: Reducer<A>,
    J: Reducer<A>,
    K: Reducer<A>, 
[src]

Updates all Reducers in the tuple in order.

Currently implemented for tuples of up to 12 elements.

Example

use reducer::Reducer;

struct ProductDetails { /* ... */ }
struct ShoppingCart { /* ... */ }
struct UserProfile { /* ... */ }

#[derive(Clone)]
enum Action {
    ViewProduct(/* ... */),
    AddToShoppingCart(/* ... */),
    UpdatePaymentPreferences(/* ... */),
    // ...
};

impl Reducer<Action> for ProductDetails {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for ShoppingCart {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for UserProfile {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

let product = ProductDetails { /* ... */ };
let cart = ShoppingCart { /* ... */ };
let user = UserProfile { /* ... */ };

let mut shop = (product, cart, user);

// `shop` itself implements Reducer<Action>
shop.reduce(Action::AddToShoppingCart( /* ... */ ));

impl<A, B, C, D, E, F, G, H, I, J, K, L> Reducer<A> for (B, C, D, E, F, G, H, I, J, K, L) where
    A: Clone,
    B: Reducer<A>,
    C: Reducer<A>,
    D: Reducer<A>,
    E: Reducer<A>,
    F: Reducer<A>,
    G: Reducer<A>,
    H: Reducer<A>,
    I: Reducer<A>,
    J: Reducer<A>,
    K: Reducer<A>,
    L: Reducer<A>, 
[src]

Updates all Reducers in the tuple in order.

Currently implemented for tuples of up to 12 elements.

Example

use reducer::Reducer;

struct ProductDetails { /* ... */ }
struct ShoppingCart { /* ... */ }
struct UserProfile { /* ... */ }

#[derive(Clone)]
enum Action {
    ViewProduct(/* ... */),
    AddToShoppingCart(/* ... */),
    UpdatePaymentPreferences(/* ... */),
    // ...
};

impl Reducer<Action> for ProductDetails {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for ShoppingCart {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for UserProfile {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

let product = ProductDetails { /* ... */ };
let cart = ShoppingCart { /* ... */ };
let user = UserProfile { /* ... */ };

let mut shop = (product, cart, user);

// `shop` itself implements Reducer<Action>
shop.reduce(Action::AddToShoppingCart( /* ... */ ));

impl<A, B, C, D, E, F, G, H, I, J, K, L, M> Reducer<A> for (B, C, D, E, F, G, H, I, J, K, L, M) where
    A: Clone,
    B: Reducer<A>,
    C: Reducer<A>,
    D: Reducer<A>,
    E: Reducer<A>,
    F: Reducer<A>,
    G: Reducer<A>,
    H: Reducer<A>,
    I: Reducer<A>,
    J: Reducer<A>,
    K: Reducer<A>,
    L: Reducer<A>,
    M: Reducer<A>, 
[src]

Updates all Reducers in the tuple in order.

Currently implemented for tuples of up to 12 elements.

Example

use reducer::Reducer;

struct ProductDetails { /* ... */ }
struct ShoppingCart { /* ... */ }
struct UserProfile { /* ... */ }

#[derive(Clone)]
enum Action {
    ViewProduct(/* ... */),
    AddToShoppingCart(/* ... */),
    UpdatePaymentPreferences(/* ... */),
    // ...
};

impl Reducer<Action> for ProductDetails {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for ShoppingCart {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

impl Reducer<Action> for UserProfile {
    fn reduce(&mut self, action: Action) {
        // ...
    }
}

let product = ProductDetails { /* ... */ };
let cart = ShoppingCart { /* ... */ };
let user = UserProfile { /* ... */ };

let mut shop = (product, cart, user);

// `shop` itself implements Reducer<Action>
shop.reduce(Action::AddToShoppingCart( /* ... */ ));
Loading content...

Implementors

Loading content...