rfham_core/fmt.rs
1//! Custom formatting trait for rfham types.
2//!
3//! [`Formatter`] is implemented by types that support configurable text rendering beyond what
4//! [`std::fmt::Display`] provides. [`FormatterOptions`] currently carries an optional decimal
5//! precision specifier.
6
7// use statements here
8
9// ------------------------------------------------------------------------------------------------
10// Public Macros
11// ------------------------------------------------------------------------------------------------
12
13// ------------------------------------------------------------------------------------------------
14// Public Types
15// ------------------------------------------------------------------------------------------------
16
17pub trait Formatter {
18 fn fmt(&self) -> String {
19 self.fmt_with(&FormatterOptions::default())
20 }
21
22 fn fmt_with(&self, options: &FormatterOptions) -> String;
23}
24
25#[derive(Clone, Copy, Debug, Default, PartialEq)]
26pub struct FormatterOptions {
27 precision: Option<usize>,
28}
29
30// ------------------------------------------------------------------------------------------------
31// Public Functions
32// ------------------------------------------------------------------------------------------------
33
34// ------------------------------------------------------------------------------------------------
35// Private Macros
36// ------------------------------------------------------------------------------------------------
37
38// ------------------------------------------------------------------------------------------------
39// Private Types
40// ------------------------------------------------------------------------------------------------
41
42// ------------------------------------------------------------------------------------------------
43// Implementations
44// ------------------------------------------------------------------------------------------------
45
46impl FormatterOptions {
47 pub const fn with_precision(mut self, precision: usize) -> Self {
48 self.precision = Some(precision);
49 self
50 }
51 pub const fn precision(&self) -> Option<usize> {
52 self.precision
53 }
54}
55// ------------------------------------------------------------------------------------------------
56// Private Functions
57// ------------------------------------------------------------------------------------------------
58
59// ------------------------------------------------------------------------------------------------
60// Sub-Modules
61// ------------------------------------------------------------------------------------------------