0

I have a Rust structure that I can deserialize:

pub struct ProcessReference {
    pub alias: Name,
    pub source: String,
    #[serde(rename = "input")]
    pub initializations: Option<HashMap<String, JsonValue>>,
}

where input is optional. This accepts TOML formats:

[[process]]
alias = "other"
source = "other.toml"

or

[[process]]
alias = "other"
source = "other.toml"
input.input1 = 1

I would like to have the input be extendable with a second value, not just the JsonValue, so that this could also be deserialized:

[[process]]
alias = "other"
source = "other.toml"
input.input1 = {1, true}

similar to that used by Cargo for dependencies:

[dependencies]
flowrlib = { path = "../flowrlib", version = "~0.7.0" }
yaml-rust = "~0.3.5"

How can I express that in Serde?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Andrew Mackenzie
  • 5,477
  • 5
  • 48
  • 70
  • See also [How to use Serde to parse a YAML file with multiple different types?](https://stackoverflow.com/q/55245914/155423) – Shepmaster Mar 20 '19 at 18:21
  • 2
    Exactly what Rust type do you expect `{1, true}` to deserialize to? It doesn't even appear to be valid TOML. – Shepmaster Mar 20 '19 at 18:22
  • No, it's probably not. I wanted to basically supply either a value (is a json value in fact) or a value and a boolean... Arrays can be mixed. I eventually had to work around it using an untagged enum which ended up more verbose than I wanted, but it works. – Andrew Mackenzie Mar 22 '19 at 16:34

0 Answers0