falco_event/types/
format.rs1use std::fmt::{Debug, Display, Formatter, LowerHex, Octal};
2
3#[doc(hidden)]
5pub struct OptionFormatter<T>(pub Option<T>);
6
7impl<T: Display> Display for OptionFormatter<T> {
8 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
9 match &self.0 {
10 Some(val) => Display::fmt(val, f),
11 None => write!(f, "NULL"),
12 }
13 }
14}
15
16impl<T: Debug> Debug for OptionFormatter<T> {
17 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
18 match &self.0 {
19 Some(val) => Debug::fmt(val, f),
20 None => write!(f, "NULL"),
21 }
22 }
23}
24
25impl<T: LowerHex> LowerHex for OptionFormatter<T> {
26 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
27 match &self.0 {
28 Some(val) => LowerHex::fmt(val, f),
29 None => write!(f, "NULL"),
30 }
31 }
32}
33
34impl<T: Octal> Octal for OptionFormatter<T> {
35 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
36 match &self.0 {
37 Some(val) => Octal::fmt(val, f),
38 None => write!(f, "NULL"),
39 }
40 }
41}