novifinancial / serde-reflection

Rust libraries and tools to help with interoperability and testing of serialization formats based on Serde.
Apache License 2.0
139 stars 42 forks source link

Viability of tracing enums without additional calls to trace_simple_type #103

Closed jerel closed 3 years ago

jerel commented 3 years ago

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?

For efficiency reasons, the current algorithm does not attempt to scan the variants of enums other than the parameter T of the main call trace_type. As a consequence, each enum type must be traced separately.

Ideally here's what I'd like to have happen:

struct User {
  account: Account
}

struct Account {
  status: Status
}

enum Status {
  Active,
  Pending,
}

// includes Status with both Active and Pending
tracer.trace_type::<User>()

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.

ma2bd commented 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:

ma2bd commented 3 years ago

I created this issue for myself: https://github.com/novifinancial/serde-reflection/issues/104