Skip to content

Commit

Permalink
Add From impls to convert between FormattingSpecs
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jul 22, 2023
1 parent 221b956 commit caf2b55
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/format/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use core::borrow::Borrow;
use core::fmt::{self, Display, Write};
use core::marker::PhantomData;

use crate::offset::{FixedOffset, Offset};
use crate::offset::{FixedOffset, Offset, Utc};
use crate::{DateTime, NaiveDate, NaiveDateTime, NaiveTime};
use crate::{Datelike, ParseError, SecondsFormat, TimeZone, Timelike, Weekday};

Expand Down Expand Up @@ -344,6 +344,21 @@ formatting_spec_impls!(NaiveDateTime, true, true, false);
formatting_spec_impls!(NaiveDate, true, false, false);
formatting_spec_impls!(NaiveTime, false, true, false);

macro_rules! formatting_spec_from_impls {
($src:ty, $dst:ty) => {
impl<I> From<FormattingSpec<$src, I>> for FormattingSpec<$dst, I> {
fn from(value: FormattingSpec<$src, I>) -> Self {
Self { items: value.items, date_time_type: PhantomData, locale: value.locale }
}
}
};
}
formatting_spec_from_impls!(NaiveTime, NaiveDateTime);
formatting_spec_from_impls!(NaiveDate, NaiveDateTime);
formatting_spec_from_impls!(NaiveTime, DateTime<Utc>);
formatting_spec_from_impls!(NaiveDate, DateTime<Utc>);
formatting_spec_from_impls!(NaiveDateTime, DateTime<Utc>);

/// A *temporary* object which can be used as an argument to [`format!`] or others.
#[derive(Debug)]
pub struct Formatter<I, Off> {
Expand Down

0 comments on commit caf2b55

Please sign in to comment.