1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use super::Waste;
use crate::piles::{Cards, Pile as _, PileMut as _};
use crate::{action, undo};
#[derive(Debug)]
pub struct Action(pub Cards);
#[derive(Debug)]
pub struct Value {
count: usize,
previous_stack_len: usize,
}
impl action::Action for Action {
type State<'s> = ();
type Value = Value;
type Error = !;
}
impl action::Target<Action> for Waste {
fn update(&mut self, Action(pile): Action, _: ()) -> Result<Value, !> {
let previous_stack_len = self.pile.left().len();
let count = pile.len();
self.pile.place(pile);
self.pile.set_right_length(count);
Ok(Value {
count,
previous_stack_len,
})
}
}
impl undo::Target<Value> for Waste {
fn revert(&mut self, value: Value) {
self.pile.take_exactly(value.count);
self.pile.set_left_length(value.previous_stack_len);
}
}