custom-display 0.1.0

A trait for implementing custom formatting logic for types
Documentation
// SPDX-FileCopyrightText: 2026 Marissa (cuddle puddle) <dev@princess.lgbt>
//
// SPDX-License-Identifier: MPL-2.0

use std::fmt::{self, Display, Formatter};

/**
 * The behavior of a [`Displayable`] when a [precision] is set.
 *
 * [`Displayable`]: crate::Displayable
 * [precision]: std::fmt#precision
 */
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum PrecisionBehavior {
    /**
     * Automatically truncate the [formatted] text to the number of characters
     * specified as the [precision].
     *
     * This is the behavior specified in [`std::fmt`] for non-numeric types.
     *
     * [formatted]: crate::CustomDisplay::fmt()
     * [precision]: std::fmt#precision
     */
    AutoTruncate,

    /**
     * The [precision] will be manually handled (or ignored) by
     * [`CustomDisplay::fmt()`] and [`CustomDisplay::width_in_chars()`].
     *
     * [precision]: std::fmt#precision
     * [`CustomDisplay::fmt()`]: crate::CustomDisplay::fmt()
     * [`CustomDisplay::width_in_chars()`]: crate::CustomDisplay::width_in_chars()
     */
    Manual,
}

impl Display for PrecisionBehavior {
    #[inline]
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match *self {
            Self::AutoTruncate => f.pad("automatically truncate"),
            Self::Manual => f.pad("handle manually"),
        }
    }
}