Skip to content

Commit

Permalink
[tracing-subscriber]: remove redundant cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
Shayne Fletcher committed Sep 6, 2023
1 parent e2b09eb commit 897cfeb
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions tracing-subscriber/src/fmt/time/chrono_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,28 @@ use crate::fmt::time::FormatTime;
/// the supported syntax.
///
/// [`chrono::format::strftime`]: https://docs.rs/chrono/0.4.9/chrono/format/strftime/index.html
#[cfg(feature = "chrono")]
#[cfg_attr(docsrs, doc(cfg(feature = "chrono")))]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ChronoFmtType {
enum ChronoFmtType {
/// Format according to the RFC 3339 convention.
Rfc3339,
/// Format according to a custom format string.
Custom(String),
}

#[cfg(feature = "chrono")]
impl Default for ChronoFmtType {
fn default() -> Self {
ChronoFmtType::Rfc3339
}
}

/// Retrieve and print the current local time.
#[cfg(feature = "chrono")]
#[cfg_attr(docsrs, doc(cfg(feature = "chrono")))]
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct ChronoLocal {
format: ChronoFmtType,
}

#[cfg(feature = "chrono")]
impl FormatTime for ChronoLocal {
fn format_time(&self, w: &mut Writer<'_>) -> alloc::fmt::Result {
let t = chrono::Local::now();
Expand All @@ -50,14 +46,12 @@ impl FormatTime for ChronoLocal {
}

/// Retrieve and print the current UTC time.
#[cfg(feature = "chrono")]
#[cfg_attr(docsrs, doc(cfg(feature = "chrono")))]
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct ChronoUtc {
format: ChronoFmtType,
}

#[cfg(feature = "chrono")]
impl FormatTime for ChronoUtc {
fn format_time(&self, w: &mut Writer<'_>) -> alloc::fmt::Result {
let t = chrono::Utc::now();
Expand All @@ -73,14 +67,10 @@ mod tests {
use crate::fmt::format::Writer;
use crate::fmt::time::FormatTime;

#[cfg(feature = "chrono")]
use super::ChronoFmtType;
#[cfg(feature = "chrono")]
use super::ChronoLocal;
#[cfg(feature = "chrono")]
use super::ChronoUtc;

#[cfg(feature = "chrono")]
#[test]
fn test_chrono_format_time_utc_default() {
let mut buf = String::new();
Expand All @@ -89,7 +79,6 @@ mod tests {
// e.g. `buf` contains "2023-08-18T19:05:08.662499+00:00"
}

#[cfg(feature = "chrono")]
#[test]
fn test_chrono_format_time_utc_custom() {
let fmt = ChronoUtc {
Expand All @@ -98,11 +87,9 @@ mod tests {
let mut buf = String::new();
let mut dst: Writer<'_> = Writer::new(&mut buf);
assert!(FormatTime::format_time(&fmt, &mut dst).is_ok());
println!("{}", buf);
// e.g. `buf` contains "Wed Aug 23 15:53:23 2023"
}

#[cfg(feature = "chrono")]
#[test]
fn test_chrono_format_time_local_default() {
let mut buf = String::new();
Expand All @@ -111,7 +98,6 @@ mod tests {
// e.g. `buf` contains "2023-08-18T14:59:08.662499-04:00".
}

#[cfg(feature = "chrono")]
#[test]
fn test_chrono_format_time_local_custom() {
let fmt = ChronoLocal {
Expand Down

0 comments on commit 897cfeb

Please sign in to comment.