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
#[cfg(feature = "failure-crate")]
use failure::Fail;
#[cfg(not(feature = "failure-crate"))]
use std::fmt::{self, Display};
#[derive(Debug)]
#[cfg_attr(feature = "failure-crate", derive(Fail))]
pub enum PermutationError {
#[cfg_attr(
feature = "failure-crate",
fail(
display = "Attempted to shuffle {}, where the highest number is {}",
shuffle, max_shuffle
)
)]
ShuffleOutOfRange { shuffle: u32, max_shuffle: u32 },
}
#[cfg(not(feature = "failure-crate"))]
impl Display for PermutationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PermutationError::ShuffleOutOfRange {
shuffle,
max_shuffle: max,
} => write!(
f,
"Attempted to shuffle {}, where the highest number is {}",
shuffle, max
),
}
}
}
pub type PermutationResult<T> = Result<T, PermutationError>;