Add structured support to kv::Value using sval #342
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's this all about?
This PR adds a new unstable feature for structured logging that lets consumers actually interact with the structure of values.
It doesn't do this by exposing its own serialization contract. Instead, it implements traits from a serialization framework called
sval
. I'm open to any philosophical debate on different approaches here!There are two commits that I think demonstrate how it fits together:
value
internals so we can add in-band serialization frameworks easily.sval
support. This is the one to look at if you're interested in what impact introducing in-band frameworks has.What is
sval
?sval
is a serialization-only framework I've been working on specifically for use inlog
.sval
supports no-std, object-safe serialization for primitives and more complex structures like maps and sequences. It absolveslog
from having to produce and maintain its own serialization contract, so it can stay focused, but lets it provide a complete serialization API for consumers.What about
serde
?serde
is the other serialization framework I've been planning to support in-band inlog
because it's ubiquitous (and does its job very well). I haven't started with it because:std
to work, because we neederased-serde
.sval
has out-of-the-box support forserde
(including in no-std environments) so adding it first already gives consumers a way to capture implementations ofserde::Serialize
.The plan is to also eventually offer
serde
support.Impact on build times
When
sval
is enabled through thekv_unstable_sval
feature, it increases our compile times by a little bit:log
Featurescargo build
time (best of 5 runs)kv_unstable
kv_unstable_sval
sval