use super::Style;
#[derive(Clone, Copy, Debug)]
pub struct Format {
pub style: Style,
pub precision: usize,
}
impl Format {
pub fn introspect() -> Self {
Self {
style: Style::Introspection,
..Default::default()
}
}
pub fn is_compressed(&self) -> bool {
self.style == Style::Compressed
}
pub fn is_introspection(&self) -> bool {
self.style == Style::Introspection
}
pub fn get_indent(&self, len: usize) -> &'static str {
static INDENT: &str = "\n ";
if self.is_compressed() {
""
} else {
&INDENT[..=len]
}
}
}
impl Default for Format {
fn default() -> Self {
Self {
style: Style::Expanded,
precision: 10,
}
}
}
pub struct Formatted<'a, T> {
pub(crate) value: &'a T,
pub(crate) format: Format,
}