[−][src]Trait reducer::Reducer
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"]
Implementations on Foreign Types
impl<A, T: ?Sized> Reducer<A> for Arc<T> where
T: Reducer<A> + Clone,
[src]
T: Reducer<A> + Clone,
Enhances a potentially unsized Reducer
with copy-on-write semantics (requires alloc
).
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 { /* ... */ } struct Actor<T> { states: Vec<T>, /* ... */ } impl Reducer<Action> for State { fn reduce(&mut self, action: Action) { // ... } } impl<T: Clone> Reactor<T> for Actor<T> { type Error = std::convert::Infallible; // TODO: use `!` once it's stable. fn react(&mut self, state: &T) -> Result<(), Self::Error> { self.states.push(state.clone()); Ok(()) } } let state = Arc::new(State { /* ... */ }); let reactor = Actor { states: vec![], /* ... */ }; let mut store = Store::new(state, reactor); store.dispatch(Action { /* ... */ }); // `state` is not cloned yet. // `reactor` now holds a reference to `state`. store.dispatch(Action { /* ... */ }); // `state` is cloned through `Arc::make_mut`.
impl<A, T> Reducer<A> for [T; 0] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 1] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 2] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 3] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 4] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 5] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 6] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 7] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 8] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 9] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 10] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 11] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 12] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 13] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 14] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 15] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 16] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 17] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 18] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 19] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 20] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 21] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 22] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 23] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 24] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 25] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 26] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 27] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 28] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 29] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 30] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 31] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T; 32] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the array in order.
Currently implemented for arrays of up to 32 elements.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T: ?Sized> Reducer<A> for Box<T> where
T: Reducer<A>,
[src]
T: Reducer<A>,
impl<A, T: ?Sized> Reducer<A> for Rc<T> where
T: Reducer<A> + Clone,
[src]
T: Reducer<A> + Clone,
Enhances a potentially unsized Reducer
with copy-on-write semantics (requires alloc
).
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 { /* ... */ } struct Actor<T> { states: Vec<T>, /* ... */ } impl Reducer<Action> for State { fn reduce(&mut self, action: Action) { // ... } } impl<T: Clone> Reactor<T> for Actor<T> { type Error = std::convert::Infallible; // TODO: use `!` once it's stable. fn react(&mut self, state: &T) -> Result<(), Self::Error> { self.states.push(state.clone()); Ok(()) } } let state = Rc::new(State { /* ... */ }); let reactor = Actor { states: vec![], /* ... */ }; let mut store = Store::new(state, reactor); store.dispatch(Action { /* ... */ }); // `state` is not cloned yet. // `reactor` now holds a reference to `state`. store.dispatch(Action { /* ... */ }); // `state` is cloned through `Rc::make_mut`.
impl<'a, A, T: ?Sized> Reducer<A> for &'a mut T where
T: Reducer<A>,
[src]
T: Reducer<A>,
Forwards the event to a potentially stack allocated Reducer
.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, T> Reducer<A> for [T] where
A: Clone,
T: Reducer<A>,
[src]
A: Clone,
T: Reducer<A>,
Updates all Reducer
s in the slice in order.
Warning: this implementation is deprecated and will be removed in a future release.
impl<A, B> Reducer<A> for (B,) where
A: Clone,
B: Reducer<A>,
[src]
A: Clone,
B: Reducer<A>,
Updates all Reducer
s 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]
A: Clone,
B: Reducer<A>,
C: Reducer<A>,
Updates all Reducer
s 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]
A: Clone,
B: Reducer<A>,
C: Reducer<A>,
D: Reducer<A>,
Updates all Reducer
s 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]
A: Clone,
B: Reducer<A>,
C: Reducer<A>,
D: Reducer<A>,
E: Reducer<A>,
Updates all Reducer
s 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]
A: Clone,
B: Reducer<A>,
C: Reducer<A>,
D: Reducer<A>,
E: Reducer<A>,
F: Reducer<A>,
Updates all Reducer
s 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]
A: Clone,
B: Reducer<A>,
C: Reducer<A>,
D: Reducer<A>,
E: Reducer<A>,
F: Reducer<A>,
G: Reducer<A>,
Updates all Reducer
s 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]
A: Clone,
B: Reducer<A>,
C: Reducer<A>,
D: Reducer<A>,
E: Reducer<A>,
F: Reducer<A>,
G: Reducer<A>,
H: Reducer<A>,
Updates all Reducer
s 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]
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>,
Updates all Reducer
s 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]
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>,
Updates all Reducer
s 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]
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>,
Updates all Reducer
s 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]
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>,
Updates all Reducer
s 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]
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>,
Updates all Reducer
s 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( /* ... */ ));