Skip to main content

ftracker_identifiers/isin/
fmt.rs

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