Skip to content

Commit

Permalink
I love you clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathspy committed Jan 3, 2022
1 parent 59a6deb commit dde97b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/formatting/formattable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ impl Formattable for Rfc3339 {}
impl Formattable for Rfc2822 {}
impl<T: Deref> Formattable for T where T::Target: Formattable {}

/// A compatibility layer to translate [`io::Write`] into [`fmt::Write`]
struct Compat<'a, W: io::Write> {
/// The [`io::Write`]r to apply the translation on
writer: &'a mut W,
/// The total bytes written into the writer so far
bytes_written: usize,
/// The last error from the writer if it returned errors
error: Option<io::Error>,
}

Expand Down Expand Up @@ -76,7 +80,7 @@ mod sealed {
compat
.error
.map(error::Format::from)
.unwrap_or_else(|| error::Format::from(fmt_error))
.unwrap_or_else(|| fmt_error)
})
}

Expand All @@ -103,7 +107,7 @@ impl<'a> sealed::Sealed for FormatItem<'a> {
time: Option<Time>,
offset: Option<UtcOffset>,
) -> Result<(), error::Format> {
Ok(match *self {
match *self {
Self::Literal(literal) => {
output.write_str(String::from_utf8_lossy(literal).as_ref())?
}
Expand All @@ -114,7 +118,9 @@ impl<'a> sealed::Sealed for FormatItem<'a> {
[] => (),
[item, ..] => item.format_into(output, date, time, offset)?,
},
})
};

Ok(())
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/formatting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub(crate) fn format_component(
offset: Option<UtcOffset>,
) -> Result<(), error::Format> {
use Component::*;
Ok(match (component, date, time, offset) {
match (component, date, time, offset) {
(Day(modifier), Some(date), ..) => fmt_day(output, date, modifier)?,
(Month(modifier), Some(date), ..) => fmt_month(output, date, modifier)?,
(Ordinal(modifier), Some(date), ..) => fmt_ordinal(output, date, modifier)?,
Expand All @@ -202,7 +202,9 @@ pub(crate) fn format_component(
(OffsetMinute(modifier), .., Some(offset)) => fmt_offset_minute(output, offset, modifier)?,
(OffsetSecond(modifier), .., Some(offset)) => fmt_offset_second(output, offset, modifier)?,
_ => return Err(error::Format::InsufficientTypeInformation),
})
};

Ok(())
}

// region: date formatters
Expand Down

0 comments on commit dde97b5

Please sign in to comment.