Deserializing into a `config::Value` loses `origin`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 3.2k
- Forks
- 265
- Avg merge
- 2h 42m
- Merged PRs (30d)
- 4
Description
I've tried searching the issue tracker for similar issues but surprisingly it seems no one has run into this so far.
Parts of my configuration is dynamic, I wanted to support this by using the exposed Value type, e.g:
struct MyConfig {
foo: String,
bar: i32,
qux: HashMap<String, config::Value>,
}
And then using Config::try_deserialize. This works, insofar as I get a correctly deserialized qux field. However, it seems that the origin is lost in this case, it gets initialized to None. If I'm following the code correctly this is because during deserialization the Value type acts as both the deserializer (coming from the root Config object) as well as the target type I'm deserializing to. However, the deserialization implementation works with any generic Deserializer, so even though we're deserializing from a Value the information can't be passed along. As far as I can tell the only proper solution would have to involve specialization which we unfortunately don't have. One workaround I can think of is using Any::downcast, but perhaps that's too heavy for an admittedly niche use-case. Are there any other workarounds that I'm missing?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Config::try_deserialize and the Value deserializer implementation in src/value.rs, especially the generic Deserializer implementation around lines 710-714. Reproduce the HashMap<String, config::Value> case and trace where origin becomes None. Done should be a confirmed approach for preserving origin or a clearly documented limitation, backed by a regression test if the behavior is changed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100