Skip to content

Commit 101cb55

Browse files
committed
Get rid of strum dependency
1 parent bb11021 commit 101cb55

File tree

2 files changed

+79
-90
lines changed

2 files changed

+79
-90
lines changed

spdlog-internal/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,4 @@ workspace = true
1414

1515
[dependencies]
1616
nom = "8.0.0"
17-
strum = { version = "0.27.0", features = ["derive"] }
18-
strum_macros = "0.27.0"
1917
thiserror = "2.0.0"

spdlog-internal/src/pattern_parser/mod.rs

Lines changed: 79 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use std::borrow::Cow;
22

3-
use strum::IntoEnumIterator as _;
4-
use strum_macros::{EnumDiscriminants, EnumIter, EnumString, IntoStaticStr};
5-
63
pub mod error;
74
mod helper;
85
pub mod parse;
@@ -11,89 +8,83 @@ mod registry;
118
pub use error::{Error, Result};
129
pub use registry::{check_custom_pattern_names, PatternRegistry};
1310

14-
#[derive(
15-
Clone, Copy, Debug, Eq, PartialEq, IntoStaticStr, EnumDiscriminants, EnumIter, EnumString,
16-
)]
17-
#[strum_discriminants(derive(IntoStaticStr))]
18-
pub enum BuiltInFormatterInner {
19-
#[strum(serialize = "weekday_name")]
20-
AbbrWeekdayName,
21-
#[strum(serialize = "weekday_name_full")]
22-
WeekdayName,
23-
#[strum(serialize = "month_name")]
24-
AbbrMonthName,
25-
#[strum(serialize = "month_name_full")]
26-
MonthName,
27-
#[strum(serialize = "datetime")]
28-
FullDateTime,
29-
#[strum(serialize = "year_short")]
30-
ShortYear,
31-
#[strum(serialize = "year")]
32-
Year,
33-
#[strum(serialize = "date_short")]
34-
ShortDate,
35-
#[strum(serialize = "date")]
36-
Date,
37-
#[strum(serialize = "month")]
38-
Month,
39-
#[strum(serialize = "day")]
40-
Day,
41-
#[strum(serialize = "hour")]
42-
Hour,
43-
#[strum(serialize = "hour_12")]
44-
Hour12,
45-
#[strum(serialize = "minute")]
46-
Minute,
47-
#[strum(serialize = "second")]
48-
Second,
49-
#[strum(serialize = "millisecond")]
50-
Millisecond,
51-
#[strum(serialize = "microsecond")]
52-
Microsecond,
53-
#[strum(serialize = "nanosecond")]
54-
Nanosecond,
55-
#[strum(serialize = "am_pm")]
56-
AmPm,
57-
#[strum(serialize = "time_12")]
58-
Time12,
59-
#[strum(serialize = "time_short")]
60-
ShortTime,
61-
#[strum(serialize = "time")]
62-
Time,
63-
#[strum(serialize = "tz_offset")]
64-
TzOffset,
65-
#[strum(serialize = "unix_timestamp")]
66-
UnixTimestamp,
67-
#[strum(serialize = "full")]
68-
Full,
69-
#[strum(serialize = "level")]
70-
Level,
71-
#[strum(serialize = "level_short")]
72-
ShortLevel,
73-
#[strum(serialize = "source")]
74-
Source,
75-
#[strum(serialize = "file_name")]
76-
SourceFilename,
77-
#[strum(serialize = "file")]
78-
SourceFile,
79-
#[strum(serialize = "line")]
80-
SourceLine,
81-
#[strum(serialize = "column")]
82-
SourceColumn,
83-
#[strum(serialize = "module_path")]
84-
SourceModulePath,
85-
#[strum(serialize = "logger")]
86-
LoggerName,
87-
#[strum(serialize = "payload")]
88-
Payload,
89-
#[strum(serialize = "kv")]
90-
KV,
91-
#[strum(serialize = "pid")]
92-
ProcessId,
93-
#[strum(serialize = "tid")]
94-
ThreadId,
95-
#[strum(serialize = "eol")]
96-
Eol,
11+
macro_rules! for_builtin_formatters {
12+
( ( $($macro_params:tt)* ) => { $($macro_impl:tt)* }; ) => {
13+
mod __private {
14+
macro_rules! __callback {
15+
( $($macro_params)* ) => { $($macro_impl)* };
16+
}
17+
pub(crate) use __callback;
18+
}
19+
__private::__callback! {
20+
AbbrWeekdayName => "weekday_name",
21+
WeekdayName => "weekday_name_full",
22+
AbbrMonthName => "month_name",
23+
MonthName => "month_name_full",
24+
FullDateTime => "datetime",
25+
ShortYear => "year_short",
26+
Year => "year",
27+
ShortDate => "date_short",
28+
Date => "date",
29+
Month => "month",
30+
Day => "day",
31+
Hour => "hour",
32+
Hour12 => "hour_12",
33+
Minute => "minute",
34+
Second => "second",
35+
Millisecond => "millisecond",
36+
Microsecond => "microsecond",
37+
Nanosecond => "nanosecond",
38+
AmPm => "am_pm",
39+
Time12 => "time_12",
40+
ShortTime => "time_short",
41+
Time => "time",
42+
TzOffset => "tz_offset",
43+
UnixTimestamp => "unix_timestamp",
44+
Full => "full",
45+
Level => "level",
46+
ShortLevel => "level_short",
47+
Source => "source",
48+
SourceFilename => "file_name",
49+
SourceFile => "file",
50+
SourceLine => "line",
51+
SourceColumn => "column",
52+
SourceModulePath => "module_path",
53+
LoggerName => "logger",
54+
Payload => "payload",
55+
KV => "kv",
56+
ProcessId => "pid",
57+
ThreadId => "tid",
58+
Eol => "eol",
59+
}
60+
};
61+
}
62+
63+
for_builtin_formatters! {
64+
( $( $variant:ident => $serialize:literal ),+ $(,)? ) => {
65+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
66+
pub enum BuiltInFormatterInner {
67+
$( $variant ),+
68+
}
69+
70+
impl BuiltInFormatterInner {
71+
fn iter() -> impl Iterator<Item = Self> {
72+
[ $( Self::$variant ),+ ].into_iter()
73+
}
74+
75+
fn struct_name(&self) -> &'static str {
76+
match self {
77+
$( Self::$variant => stringify!($variant), )+
78+
}
79+
}
80+
81+
fn placeholder(&self) -> &'static str {
82+
match self {
83+
$( Self::$variant => $serialize, )+
84+
}
85+
}
86+
}
87+
};
9788
}
9889

9990
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -106,12 +97,12 @@ impl BuiltInFormatter {
10697

10798
#[must_use]
10899
pub fn struct_name(&self) -> &'static str {
109-
BuiltInFormatterInnerDiscriminants::from(self.0).into()
100+
self.0.struct_name()
110101
}
111102

112103
#[must_use]
113104
pub fn placeholder(&self) -> &'static str {
114-
self.0.into()
105+
self.0.placeholder()
115106
}
116107

117108
#[must_use]

0 commit comments

Comments
 (0)