use_combinatorics/
error.rs1use core::fmt;
2use std::error::Error;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum CombinatoricsError {
7 KExceedsN {
9 n: u64,
11 k: u64,
13 },
14 FactorialOverflow(u64),
16 PermutationOverflow {
18 n: u64,
20 k: u64,
22 },
23 CombinationOverflow {
25 n: u64,
27 k: u64,
29 },
30}
31
32impl fmt::Display for CombinatoricsError {
33 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
34 match self {
35 Self::KExceedsN { n, k } => {
36 write!(
37 formatter,
38 "k must be less than or equal to n, got k={k}, n={n}"
39 )
40 },
41 Self::FactorialOverflow(n) => {
42 write!(formatter, "factorial overflowed u128 for n={n}")
43 },
44 Self::PermutationOverflow { n, k } => {
45 write!(formatter, "permutations overflowed u128 for n={n}, k={k}")
46 },
47 Self::CombinationOverflow { n, k } => {
48 write!(formatter, "combinations overflowed u128 for n={n}, k={k}")
49 },
50 }
51 }
52}
53
54impl Error for CombinatoricsError {}