1use crate::sponge::Pattern;
2use std::fmt::Write;
3
4#[derive(Debug, Clone)]
5pub enum Error {
6 SqueezeBeforeAbsorb,
8 PatternOutOfBound,
10 UnexpectedAbsorb,
12 UnexpectedSqueeze,
14 FinishMismatch(Box<Mismatch>),
16}
17
18#[derive(Clone)]
19pub struct Mismatch {
20 expected: Vec<Pattern>,
21 found: Vec<Pattern>,
22}
23
24impl std::fmt::Debug for Mismatch {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 let expected = Mismatch::debug_pattern(&self.expected)?;
27 let found = Mismatch::debug_pattern(&self.found)?;
28 f.debug_struct("Mismatch")
29 .field("expected", &expected)
30 .field("found ", &found)
31 .finish()
32 }
33}
34
35impl Mismatch {
36 pub(crate) fn new(expected: Vec<Pattern>, found: Vec<Pattern>) -> Self {
37 Self { expected, found }
38 }
39 fn debug_pattern(pattern: &[Pattern]) -> Result<String, std::fmt::Error> {
40 let mut string = String::new();
41 for p in pattern {
42 match p {
43 Pattern::Absorb(n) => {
44 write!(&mut string, "A{:02} ", n)?;
45 }
46 Pattern::Squeeze(n) => {
47 write!(&mut string, "S{:02} ", n)?;
48 }
49 }
50 }
51 Ok(string)
52 }
53}