//! A trait that can be used to format an item from its components. use core::ops::Deref; use std::io; use crate::format_description::well_known::iso8601::EncodedConfig; use crate::format_description::well_known::{Iso8601, Rfc2822, Rfc3339}; use crate::format_description::{FormatItem, OwnedFormatItem}; use crate::formatting::{ format_component, format_number_pad_zero, iso8601, write, MONTH_NAMES, WEEKDAY_NAMES, }; use crate::{error, Date, Time, UtcOffset}; /// A type that can be formatted. #[cfg_attr(__time_03_docs, doc(notable_trait))] pub trait Formattable: sealed::Sealed {} impl Formattable for FormatItem<'_> {} impl Formattable for [FormatItem<'_>] {} impl Formattable for OwnedFormatItem {} impl Formattable for [OwnedFormatItem] {} impl Formattable for Rfc3339 {} impl Formattable for Rfc2822 {} impl Formattable for Iso8601 {} impl Formattable for T where T::Target: Formattable {} /// Seal the trait to prevent downstream users from implementing it. mod sealed { #[allow(clippy::wildcard_imports)] use super::*; /// Format the item using a format description, the intended output, and the various components. pub trait Sealed { /// Format the item into the provided output, returning the number of bytes written. fn format_into( &self, output: &mut impl io::Write, date: Option, time: Option