mirror of
				https://github.com/chronotope/chrono.git
				synced 2025-11-04 07:23:49 +00:00 
			
		
		
		
	Add ?Sized bound to related methods of DelayedFormat::write_to
				
					
				
			This commit is contained in:
		
							parent
							
								
									b4b9aa580c
								
							
						
					
					
						commit
						59d5f46f17
					
				@ -109,7 +109,7 @@ impl<'a, I: Iterator<Item = B> + Clone, B: Borrow<Item<'a>>> DelayedFormat<I> {
 | 
				
			|||||||
    /// let mut buffer = String::new();
 | 
					    /// let mut buffer = String::new();
 | 
				
			||||||
    /// let _ = df.write_to(&mut buffer);
 | 
					    /// let _ = df.write_to(&mut buffer);
 | 
				
			||||||
    /// ```
 | 
					    /// ```
 | 
				
			||||||
    pub fn write_to(&self, w: &mut impl Write) -> fmt::Result {
 | 
					    pub fn write_to(&self, w: &mut (impl Write + ?Sized)) -> fmt::Result {
 | 
				
			||||||
        for item in self.items.clone() {
 | 
					        for item in self.items.clone() {
 | 
				
			||||||
            match *item.borrow() {
 | 
					            match *item.borrow() {
 | 
				
			||||||
                Item::Literal(s) | Item::Space(s) => w.write_str(s),
 | 
					                Item::Literal(s) | Item::Space(s) => w.write_str(s),
 | 
				
			||||||
@ -124,14 +124,19 @@ impl<'a, I: Iterator<Item = B> + Clone, B: Borrow<Item<'a>>> DelayedFormat<I> {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[cfg(feature = "alloc")]
 | 
					    #[cfg(feature = "alloc")]
 | 
				
			||||||
    fn format_numeric(&self, w: &mut impl Write, spec: &Numeric, pad: Pad) -> fmt::Result {
 | 
					    fn format_numeric(
 | 
				
			||||||
 | 
					        &self,
 | 
				
			||||||
 | 
					        w: &mut (impl Write + ?Sized),
 | 
				
			||||||
 | 
					        spec: &Numeric,
 | 
				
			||||||
 | 
					        pad: Pad,
 | 
				
			||||||
 | 
					    ) -> fmt::Result {
 | 
				
			||||||
        use self::Numeric::*;
 | 
					        use self::Numeric::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        fn write_one(w: &mut impl Write, v: u8) -> fmt::Result {
 | 
					        fn write_one(w: &mut (impl Write + ?Sized), v: u8) -> fmt::Result {
 | 
				
			||||||
            w.write_char((b'0' + v) as char)
 | 
					            w.write_char((b'0' + v) as char)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        fn write_two(w: &mut impl Write, v: u8, pad: Pad) -> fmt::Result {
 | 
					        fn write_two(w: &mut (impl Write + ?Sized), v: u8, pad: Pad) -> fmt::Result {
 | 
				
			||||||
            let ones = b'0' + v % 10;
 | 
					            let ones = b'0' + v % 10;
 | 
				
			||||||
            match (v / 10, pad) {
 | 
					            match (v / 10, pad) {
 | 
				
			||||||
                (0, Pad::None) => {}
 | 
					                (0, Pad::None) => {}
 | 
				
			||||||
@ -142,7 +147,7 @@ impl<'a, I: Iterator<Item = B> + Clone, B: Borrow<Item<'a>>> DelayedFormat<I> {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        #[inline]
 | 
					        #[inline]
 | 
				
			||||||
        fn write_year(w: &mut impl Write, year: i32, pad: Pad) -> fmt::Result {
 | 
					        fn write_year(w: &mut (impl Write + ?Sized), year: i32, pad: Pad) -> fmt::Result {
 | 
				
			||||||
            if (1000..=9999).contains(&year) {
 | 
					            if (1000..=9999).contains(&year) {
 | 
				
			||||||
                // fast path
 | 
					                // fast path
 | 
				
			||||||
                write_hundreds(w, (year / 100) as u8)?;
 | 
					                write_hundreds(w, (year / 100) as u8)?;
 | 
				
			||||||
@ -153,7 +158,7 @@ impl<'a, I: Iterator<Item = B> + Clone, B: Borrow<Item<'a>>> DelayedFormat<I> {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        fn write_n(
 | 
					        fn write_n(
 | 
				
			||||||
            w: &mut impl Write,
 | 
					            w: &mut (impl Write + ?Sized),
 | 
				
			||||||
            n: usize,
 | 
					            n: usize,
 | 
				
			||||||
            v: i64,
 | 
					            v: i64,
 | 
				
			||||||
            pad: Pad,
 | 
					            pad: Pad,
 | 
				
			||||||
@ -214,7 +219,7 @@ impl<'a, I: Iterator<Item = B> + Clone, B: Borrow<Item<'a>>> DelayedFormat<I> {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[cfg(feature = "alloc")]
 | 
					    #[cfg(feature = "alloc")]
 | 
				
			||||||
    fn format_fixed(&self, w: &mut impl Write, spec: &Fixed) -> fmt::Result {
 | 
					    fn format_fixed(&self, w: &mut (impl Write + ?Sized), spec: &Fixed) -> fmt::Result {
 | 
				
			||||||
        use Fixed::*;
 | 
					        use Fixed::*;
 | 
				
			||||||
        use InternalInternal::*;
 | 
					        use InternalInternal::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -387,7 +392,7 @@ pub fn format_item(
 | 
				
			|||||||
#[cfg(any(feature = "alloc", feature = "serde"))]
 | 
					#[cfg(any(feature = "alloc", feature = "serde"))]
 | 
				
			||||||
impl OffsetFormat {
 | 
					impl OffsetFormat {
 | 
				
			||||||
    /// Writes an offset from UTC with the format defined by `self`.
 | 
					    /// Writes an offset from UTC with the format defined by `self`.
 | 
				
			||||||
    fn format(&self, w: &mut impl Write, off: FixedOffset) -> fmt::Result {
 | 
					    fn format(&self, w: &mut (impl Write + ?Sized), off: FixedOffset) -> fmt::Result {
 | 
				
			||||||
        let off = off.local_minus_utc();
 | 
					        let off = off.local_minus_utc();
 | 
				
			||||||
        if self.allow_zulu && off == 0 {
 | 
					        if self.allow_zulu && off == 0 {
 | 
				
			||||||
            w.write_char('Z')?;
 | 
					            w.write_char('Z')?;
 | 
				
			||||||
@ -496,7 +501,7 @@ pub enum SecondsFormat {
 | 
				
			|||||||
#[inline]
 | 
					#[inline]
 | 
				
			||||||
#[cfg(any(feature = "alloc", feature = "serde"))]
 | 
					#[cfg(any(feature = "alloc", feature = "serde"))]
 | 
				
			||||||
pub(crate) fn write_rfc3339(
 | 
					pub(crate) fn write_rfc3339(
 | 
				
			||||||
    w: &mut impl Write,
 | 
					    w: &mut (impl Write + ?Sized),
 | 
				
			||||||
    dt: NaiveDateTime,
 | 
					    dt: NaiveDateTime,
 | 
				
			||||||
    off: FixedOffset,
 | 
					    off: FixedOffset,
 | 
				
			||||||
    secform: SecondsFormat,
 | 
					    secform: SecondsFormat,
 | 
				
			||||||
@ -560,7 +565,7 @@ pub(crate) fn write_rfc3339(
 | 
				
			|||||||
#[cfg(feature = "alloc")]
 | 
					#[cfg(feature = "alloc")]
 | 
				
			||||||
/// write datetimes like `Tue, 1 Jul 2003 10:52:37 +0200`, same as `%a, %d %b %Y %H:%M:%S %z`
 | 
					/// write datetimes like `Tue, 1 Jul 2003 10:52:37 +0200`, same as `%a, %d %b %Y %H:%M:%S %z`
 | 
				
			||||||
pub(crate) fn write_rfc2822(
 | 
					pub(crate) fn write_rfc2822(
 | 
				
			||||||
    w: &mut impl Write,
 | 
					    w: &mut (impl Write + ?Sized),
 | 
				
			||||||
    dt: NaiveDateTime,
 | 
					    dt: NaiveDateTime,
 | 
				
			||||||
    off: FixedOffset,
 | 
					    off: FixedOffset,
 | 
				
			||||||
) -> fmt::Result {
 | 
					) -> fmt::Result {
 | 
				
			||||||
@ -605,7 +610,7 @@ pub(crate) fn write_rfc2822(
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Equivalent to `{:02}` formatting for n < 100.
 | 
					/// Equivalent to `{:02}` formatting for n < 100.
 | 
				
			||||||
pub(crate) fn write_hundreds(w: &mut impl Write, n: u8) -> fmt::Result {
 | 
					pub(crate) fn write_hundreds(w: &mut (impl Write + ?Sized), n: u8) -> fmt::Result {
 | 
				
			||||||
    if n >= 100 {
 | 
					    if n >= 100 {
 | 
				
			||||||
        return Err(fmt::Error);
 | 
					        return Err(fmt::Error);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user