Closed Lancern closed 2 years ago
So here are the problems that need to be fixed and problems that are still unresolved after the first round of review:
{^...$}
to {^...}
;-
with _
in pattern names;TimeDate::tz_offset_str
into a lazy closure;{year}-{month}-{day}
(the ISO 8601 date format);Formatter::clone_box
for PatternFormatter
;Pattern
structpub(crate)
method for Level
that returns the level names;Loc
pattern;P: Pattern
bound to PatternFormatter<P>
;~
UPDATE: Referred to this answer, bound trait only on all impl
blocks, struct
keeps unbounded.ColorRange
to StyleRange
.spdlog_macros::pattern
directly from spdlog
rather than wrapping it behind a macro by example;pattern_formatter!
.Looks like all problems from the first round of review have been solved! 🎉
There should be only one final question left, and I've been thinking about it. I'd like to try to split the current trait Pattern
into two concepts, struct Pattern
+ trait PatternEntity
(or PatternFlag
or other name?).
The motivations:
Pattern
is supposed to be a combination, but now a single placeholder is also considered a Pattern
. A formatter with only a single placeholder should not make much sense to users.pattern!("template")
will return a struct Pattern<(impl PatternEntity, impl PatternEntity, ...)>
, and we need a wrapper like this to prevent users from accessing the tuple, as it is implementation details.fn Pattern::compile("template") -> Pattern<RuntimePattern>
for this purpose.Pattern
, Template
and Placeholder
, which can be confusing for users to read.Simply put, this split just adds a wrapper to the existing trait Pattern
combination.
@Lancern What is your opinion? :)
I'd like to try to split the current trait Pattern into two concepts, struct Pattern + trait PatternEntity (or PatternFlag or other name?).
I'd argue that this actually limits the ability to combine different patterns. An important usage is that, users can use built-in patterns as building blocks for their own patterns; and again, these user-crafted patterns can also be used as building blocks for even larger patterns. If pattern!
returns a struct Pattern
, it won't be able to be used for building larger patterns, unless we implement trait PatternEntity
for struct Pattern
. But then why we split trait Pattern
in the first place?
Semantically, a Pattern is supposed to be a combination, but now a single placeholder is also considered a Pattern. A formatter with only a single placeholder should not make much sense to users.
Patterns can be freely combined does not mean patterns are combinations. A single placeholder as a pattern can also be useful; for instance, {full}
or {payload}
.
Yeah, you're right, I'll drop that idea.
I'll do some more checking and cleanup, and if there are no more issues this PR should be merged in the next few days.
This PR introduces pattern-based formatters.
Related issue: #10