rfham-core 0.1.1

Core data types for RF-Ham libraries.
Documentation
//! Custom formatting trait for rfham types.
//!
//! [`Formatter`] is implemented by types that support configurable text rendering beyond what
//! [`std::fmt::Display`] provides. [`FormatterOptions`] currently carries an optional decimal
//! precision specifier.

// use statements here

// ------------------------------------------------------------------------------------------------
// Public Macros
// ------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------
// Public Types
// ------------------------------------------------------------------------------------------------

pub trait Formatter {
    fn fmt(&self) -> String {
        self.fmt_with(&FormatterOptions::default())
    }

    fn fmt_with(&self, options: &FormatterOptions) -> String;
}

#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct FormatterOptions {
    precision: Option<usize>,
}

// ------------------------------------------------------------------------------------------------
// Public Functions
// ------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------
// Private Macros
// ------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------
// Private Types
// ------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------
// Implementations
// ------------------------------------------------------------------------------------------------

impl FormatterOptions {
    pub const fn with_precision(mut self, precision: usize) -> Self {
        self.precision = Some(precision);
        self
    }
    pub const fn precision(&self) -> Option<usize> {
        self.precision
    }
}
// ------------------------------------------------------------------------------------------------
// Private Functions
// ------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------
// Sub-Modules
// ------------------------------------------------------------------------------------------------