Closed jerel closed 3 years ago
Thanks for the note. I should probably make a pass on the documentation to clarify the current tradeoff and start thinking about future algorithmic improvements.
From the back of my memory:
tracer.trace_type::<User>()
will discover Status
, Status::Active
, and the fact this enum has two variants, allowing us to return an error MissingVariant
. (Just to be clear: here you are supposed to call tracer.trace_type::<Status>()
at least once before tracer.trace_type::<User>()
.)tracer.trace_type::<T>()
consists in repeating tracer.trace_type_once::<T>()
many times until we have discovered all the variants of T
. Importantly, if T is a recursive type, the algorithm always chooses the first variant as a "base case" during the recursive traversal. (Type signatures require us to produce a value of type T
whenever T
is visited.)enum Foo { Next(Box<Foo>), Nil }
but at least it does on enum Foo { Nil, Next(Box<Foo>) }
(which is how most people write their code anyway). I agree that it would be nice to enforce both termination and coverage on the first call to tracer.trace_type::<T>()
for any "reasonable" type T
but this requires some non-trivial improvement of the algorithm.I created this issue for myself: https://github.com/novifinancial/serde-reflection/issues/104
I'm not sure if this is a feature request or just a request for clarification on the current state of things...
I'm using serde-reflection in my project (thank you!) and it works beautifully to trace a struct to discover child types. This means that I can construct a full representation from just one struct. Except for enums?
Ideally here's what I'd like to have happen:
I noticed in #98 that it's apparently possible to trace an enum so would it make sense to have a config option to opt in to having child enums traced? How inefficient is it currently? Just curious what my options are here.