1//! Module for new types that isolate complext formatting
2use std::fmt;
3
4use owo_colors::OwoColorize;
5
6pub(crate) struct LocationSection<'a>(
7 pub(crate) Option<&'a std::panic::Location<'a>>,
8 pub(crate) crate::config::Theme,
9);
10
11impl fmt::Display for LocationSection<'_> {
12 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13 let theme: Theme = self.1;
14 // If known, print panic location.
15 if let Some(loc: &Location<'_>) = self.0 {
16 write!(f, "{}", loc.file().style(theme.panic_file))?;
17 write!(f, ":")?;
18 write!(f, "{}", loc.line().style(theme.panic_line_number))?;
19 } else {
20 write!(f, "<unknown>")?;
21 }
22
23 Ok(())
24 }
25}
26