utls 0.7.5

A simple utilities library for stuff I actually use sometimes, with a large focus on convenience and lack of dependencies.
Documentation
//! Display implementations for anything that would benefit from them
#[cfg(feature = "watcher")]
use crate::watcher::Watcher;
use std::fmt;

#[cfg(feature = "progress_bar")]
use super::prog::*;

// Display implementation for PBState
#[cfg(feature = "progress_bar")]
impl fmt::Display for PBState {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            PBState::Running => write!(f, "Running"),
            PBState::Finished => write!(f, "Finished"),
            PBState::Abandoned => write!(f, "Abandoned (failed?)"),
        }
    }
}

// Display implementation for PBStatistics
#[cfg(feature = "progress_bar")]
impl fmt::Display for PBStatistics {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        writeln!(f, "Progress Bar Statistics:")?;
        writeln!(f, "Target Update Frequency: {:?}", self.target_update_freq)?;
        writeln!(
            f,
            "Minimum Update Interval: {:?}",
            self.actual_min_update.unwrap_or_default()
        )?;
        writeln!(
            f,
            "Maximum Update Interval: {:?}",
            self.actual_max_update.unwrap_or_default()
        )?;
        writeln!(
            f,
            "Average Update Interval: {:?}",
            self.actual_avg_update.unwrap_or_default()
        )?;
        writeln!(f, "Total Updates: {}", self.total_updates)?;
        writeln!(
            f,
            "Total Duration: {:?}",
            self.total_duration.unwrap_or_default()
        )?;
        write!(f, "Advanced Statistics Enabled: {}", self.adv_enabled)
    }
}

#[cfg(feature = "progress_bar")]
impl fmt::Display for PB {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.gen_immut(),)
    }
}

#[cfg(feature = "watcher")]
impl<T: PartialEq + Send + 'static + std::fmt::Display> fmt::Display for Watcher<T> {
    // Copied directly from fmt/mod.rs
    ///  Formats the value using the given formatter.
    /// # Errors

    /// This function should return [`Err`] if, and only if, the provided [`Formatter`] returns [`Err`].
    /// String formatting is considered an infallible operation; this function only
    /// returns a [`Result`] because writing to the underlying stream might fail and it must
    /// provide a way to propagate the fact that an error has occurred back up the stack.
    ///
    /// # Examples
    ///
    /// ```
    /// use std::fmt;
    ///
    /// struct Position {
    ///     longitude: f32,
    ///     latitude: f32,
    /// }
    ///
    /// impl fmt::Display for Position {
    ///     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    ///         write!(f, "({}, {})", self.longitude, self.latitude)
    ///     }
    /// }
    ///
    /// assert_eq!(
    ///     "(1.987, 2.983)",
    ///     format!("{}", Position { longitude: 1.987, latitude: 2.983, }),
    /// );
    /// ```
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "Value: {}\nChanged: {:#?}\nShutdown: {:#?}",
            self.value.lock().unwrap(),
            self.changed.lock().unwrap(),
            self.shutdown.lock().unwrap()
        )
    }
}

#[cfg(feature = "watcher")]
impl<T: PartialEq + Send + 'static + std::fmt::Debug> Watcher<T> {
    /// This is used when `T` does not implement Display, but it does implement Debug
    #[allow(dead_code)]
    pub fn fmt_dbg(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "Value: {:#?}\nChanged: {:#?}\nShutdown: {:#?}",
            self.value.lock().unwrap(),
            self.changed.lock().unwrap(),
            self.shutdown.lock().unwrap()
        )
    }
}