ppvm_pauli_word/pattern/
display.rs1use super::data::{Decorated, NotIdentity, OpPattern, PauliPattern};
5
6impl std::fmt::Display for NotIdentity {
7 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8 match self {
9 NotIdentity::X => write!(f, "X"),
10 NotIdentity::Y => write!(f, "Y"),
11 NotIdentity::Z => write!(f, "Z"),
12 }
13 }
14}
15
16impl std::fmt::Display for OpPattern {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 match self {
19 OpPattern::Identity => write!(f, "I"),
20 OpPattern::Single(not_identity) => write!(f, "{}", not_identity),
21 OpPattern::Double(left, right) => write!(f, "[{}{}]", left, right),
22 OpPattern::AnyNonIdentity => write!(f, "[XYZ]"),
23 OpPattern::SingleOrIdentity(not_identity) => write!(f, "{}?", not_identity),
24 OpPattern::DoubleOrIdentity(left, right) => write!(f, "[{}{}]?", left, right),
25 OpPattern::AnyPauliOrIdentity => write!(f, "_"),
26 }
27 }
28}
29
30impl std::fmt::Display for Decorated {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 match self {
33 Decorated::Position(op, pos) => write!(f, "{}{}", op, pos),
34 Decorated::Star(op) => write!(f, "{}*", op),
35 Decorated::Repeat(op, count) => write!(f, "{}{{{}}}", op, count),
36 }
37 }
38}
39
40impl std::fmt::Display for PauliPattern {
41 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 for pattern in &self.0 {
43 write!(f, "{}", pattern)?;
44 }
45 Ok(())
46 }
47}