-
Notifications
You must be signed in to change notification settings - Fork 583
Span tracking #1246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Span tracking #1246
Conversation
@@ -36,6 +35,8 @@ pub struct Deserializer<R> { | |||
single_precision: bool, | |||
#[cfg(feature = "unbounded_depth")] | |||
disable_recursion_limit: bool, | |||
#[cfg(feature = "spanned")] | |||
spanned_enabled: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Design note on why I decided to only add support for spans when explicitly enabled (e.g., by calling from_str_spanned
instead of from_str
):
Otherwise, this would be a breaking change for anyone passing a struct whose Deserialize
implementation calls deserialize_struct
on serde_json's Deserializer
with arguments satisfying is_spanned
. Admittedly, this is highly unlikely, but I'd rather stick to hard SemVer rules. If you disagree, I'm happy to put in this functionality unconditionally.
Another benefit of this design is that when fleshing out the implementation, this allows me to move the position tracking into the Deserializer
(as Read
's tracking seems to be insufficient) and only engage in the counting/tracking if the user indicated that they're interested in span information in the first place (by calling one of the new APIs).
I can't comment as a maintainer of For instance,
It would also be helpful to expand on the motivating use cases in tests some more. For users that are are deriving
Each of these deserve asserts that demonstrate the additional information is valuable. If you can show that this can do multiple uses cases, it's very convincing. Needing lots of maintainance for niche gains will not be easy to add to any OSS crate. The Also probably cut the Then in comparison, I'm not certain the motivation for |
Introducing optional span tracking (line, column, byte offset).
The feature is behind a new feature flag called
spanned
. It introducesSpanned<T>
, with wich you can get serde_json (when calling the appropriate deserializer) to inject span information into customDeserialize
types.SpannedValue
a copy ofValue
that usesSpanned<T>
to provide span information.This PR still needs a bit of fixing up:
Read::position
as itscolumn
isn't what we want and itsline
is slow to computeAnd then a good chunk of polishing:
SpannedValue
functionality is 90% copy-pasta fromValue
)However, before I proceed with any of that, and since I've already put a good amount hours into this, I'd first like to get initial feedback on/review of the general design (API, outlined provided functionality).
Here's the gist of how it'd work
Sample code with output
Produces
Closes: #637