Skip to main content

ftracker_identifiers/cfi/
fmt.rs

1//! `Display`/`Debug` for [`Cfi`].
2//!
3//! A CFI has no conventional punctuated form: its canonical rendering *is* the
4//! compact 6-character string. There is therefore no separate zero-allocation formatted-string
5//! helper — [`Cfi::as_str`](Cfi::as_str) already returns the canonical form.
6
7use crate::cfi::Cfi;
8use core::fmt;
9
10impl fmt::Display for Cfi {
11    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12        f.write_str(self.as_str())
13    }
14}
15
16impl fmt::Debug for Cfi {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        f.debug_tuple("Cfi").field(&self.as_str()).finish()
19    }
20}
21
22#[cfg(test)]
23mod tests {
24    use crate::cfi::Cfi;
25    use alloc::format;
26    use alloc::string::ToString;
27
28    #[test]
29    fn display_is_the_canonical_string() {
30        let cfi = Cfi::parse("ESVUFR").unwrap();
31        assert_eq!(cfi.to_string(), "ESVUFR");
32    }
33
34    #[test]
35    fn debug_is_readable() {
36        let cfi = Cfi::parse("ESVUFR").unwrap();
37        assert_eq!(format!("{cfi:?}"), "Cfi(\"ESVUFR\")");
38    }
39}