Skip to content

Commit 5fffe00

Browse files
committed
feat: Put time dependency behind a feature flag
1 parent 022fb93 commit 5fffe00

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tracing-subscriber = { version = "0.3", default-features = false, features = ["r
1414
nu-ansi-term = "0.46.0"
1515
atty = "0.2"
1616
tracing-log = { version = "0.1", optional = true }
17-
time = { version = "0.3.20", features = ["formatting", "local-offset"] }
17+
time = { version = "0.3.20", optional = true, features = ["formatting", "local-offset"] }
1818

1919
[features]
2020
default = ["tracing-log"]

src/time.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
///
66
/// Notable default implementations of this trait are [LocalDateTime] and `()`.
77
/// The former prints the current time as reported by [time's OffsetDateTime]
8-
/// (note that it may panic! make sure to check out the docs for the [LocalDateTime]),
8+
/// (note that it requires a `time` feature to be enabled and may panic!
9+
/// make sure to check out the docs for the [LocalDateTime]),
910
/// and the latter does not print the current time at all.
1011
///
1112
/// Inspired by the [FormatTime] trait from [tracing-subscriber].
@@ -34,9 +35,11 @@ impl FormatTime for () {
3435
////////////////////////////////////////////////////////////////////////////////////////////////////
3536

3637
/// Retrieve and print the current wall-clock time in UTC timezone.
38+
#[cfg(feature = "time")]
3739
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
3840
pub struct UtcDateTime;
3941

42+
#[cfg(feature = "time")]
4043
impl FormatTime for UtcDateTime {
4144
fn format_time(&self, w: &mut impl std::fmt::Write) -> std::fmt::Result {
4245
let time = time::OffsetDateTime::now_utc();
@@ -56,9 +59,11 @@ impl FormatTime for UtcDateTime {
5659
// NB:
5760
// Can't use `tracing_subscriber::fmt::time::SystemTime` since it uses
5861
// private `datetime` module to format the actual time.
62+
#[cfg(feature = "time")]
5963
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
6064
pub struct LocalDateTime;
6165

66+
#[cfg(feature = "time")]
6267
impl FormatTime for LocalDateTime {
6368
fn format_time(&self, w: &mut impl std::fmt::Write) -> std::fmt::Result {
6469
let time = time::OffsetDateTime::now_local().expect("time offset cannot be determined");

0 commit comments

Comments
 (0)