If I have a JSON value with unknown layout I can deserialise it with serde_json
using serde_json::Value
:
#[derive(Deserialize)]
struct Foo {
unknown: serde_json::Value,
}
Similarly I can do the same with CBOR:
#[derive(Deserialize)]
struct Foo {
unknown: serde_cbor::Value,
}
But what if I want a single data structure that can be loaded from JSON or CBOR. I effectively want this:
enum UnknownValue {
Json(serde_json::Value),
Cbor(serde_cbor::Value),
}
#[derive(Deserialize)]
struct Foo {
unknown: UnknownValue,
}
Is there any way to do this so that I can deserialise JSON or CBOR into this struct?