From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- vendor/time/src/formatting/formattable.rs | 304 ++++++++++++++++++++++++++++++ 1 file changed, 304 insertions(+) create mode 100644 vendor/time/src/formatting/formattable.rs (limited to 'vendor/time/src/formatting/formattable.rs') diff --git a/vendor/time/src/formatting/formattable.rs b/vendor/time/src/formatting/formattable.rs new file mode 100644 index 000000000..7fee2fbea --- /dev/null +++ b/vendor/time/src/formatting/formattable.rs @@ -0,0 +1,304 @@ +//! 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