Skip to content

Deserializing into a config::Value loses origin #698

@andor-ra2

Description

@andor-ra2

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions