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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use crate*;
;
/// Helper for implementing a [`DieOnce`] from a [`FnOnce`] that takes a [`Fate`].
///
/// # Examples
///
/// ```
/// use dicetest::prelude::*;
/// use dicetest::{Prng, Limit};
///
/// let mut prng = Prng::from_seed(0x5EED.into());
/// let limit = Default::default();
/// let mut fate = Fate::new(&mut prng, limit);
///
/// let zero_or_one = fate.roll(dice::from_fn_once(|mut fate| fate.next_number() % 2));
/// assert!(zero_or_one == 0 || zero_or_one == 1);
///
/// #[derive(Debug, PartialEq, Eq)]
/// struct CannotBeCloned;
/// let not_a_clone = fate.roll(dice::from_fn_once(|_| CannotBeCloned));
/// assert_eq!(not_a_clone, CannotBeCloned);
/// ```
/// Helper for implementing a [`Die`] from a [`Fn`] that takes a [`Fate`].
///
/// # Examples
///
/// ```
/// use dicetest::prelude::*;
/// use dicetest::{Prng, Limit};
///
/// let mut prng = Prng::from_seed(0x5EED.into());
/// let limit = Limit::default();
/// let mut fate = Fate::new(&mut prng, limit);
///
/// let zero_or_one = fate.roll(dice::from_fn(|mut fate| fate.next_number() % 2));
/// assert!(zero_or_one == 0 || zero_or_one == 1);
///
/// let vec = vec![0, 1, 2];
/// let cloning_die = dice::from_fn(move |_| vec.clone());
/// for _ in 0..10 {
/// assert_eq!(fate.roll(&cloning_die), vec![0, 1, 2]);
/// }
/// ```