1 /// Reset terminal formatting
2 #[allow(clippy::exhaustive_structs)]
3 #[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
4 pub struct Reset;
5 
6 impl Reset {
7     /// Render the ANSI code
8     ///
9     /// `Reset` also implements `Display` directly, so calling this method is optional.
10     #[inline]
render(self) -> impl core::fmt::Display + Copy11     pub fn render(self) -> impl core::fmt::Display + Copy {
12         self
13     }
14 }
15 
16 impl core::fmt::Display for Reset {
fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result17     fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
18         f.write_str(RESET)
19     }
20 }
21 
22 pub(crate) const RESET: &str = "\x1B[0m";
23 
24 #[cfg(test)]
25 #[cfg(feature = "std")]
26 mod test {
27     use super::*;
28 
29     #[test]
print_size_of()30     fn print_size_of() {
31         use std::mem::size_of;
32         dbg!(size_of::<Reset>());
33     }
34 
35     #[test]
no_align()36     fn no_align() {
37         #[track_caller]
38         fn assert_no_align(d: impl core::fmt::Display) {
39             let expected = format!("{d}");
40             let actual = format!("{d:<10}");
41             assert_eq!(expected, actual);
42         }
43 
44         assert_no_align(Reset);
45         assert_no_align(Reset.render());
46     }
47 }
48