Closed lquerel closed 6 months ago
Would serde_json::from_value and serde_yaml::from_value be sufficient?
use serde_json::json;
fn main() {
let j:serde_json::Value = json!({
"fingerprint": "0xF9BA143B95FF6D82",
"location": "Menlo Park, CA",
"Hello": [
1,
"Foo"
]
});
println!("{j:#?}");
let yaml = "
- 1
- [0, 0, 0]
- {x: 1.0, y: 2.0}
";
let k : serde_yaml::Value = serde_yaml::from_str(&yaml).unwrap();
println!("{k:#?}");
// Convert serde_json::Value to regorus::Value, consuming it.
let u: regorus::Value = serde_json::from_value(j).unwrap();
println!("{u:#?}");
// Convert serde_yaml::Value to regorus::Value, consuming it.
let v: regorus::Value = serde_yaml::from_value(k).unwrap();
println!("{v:#?}");
}
Sorry, and shame on me, I forgot the basics...
No worries. I'm thinking of adding a From<serde_json::Value>
to regorus::Value
since serde_json::from_value
may not be that intuitive.
That will make things straightforward
This type of conversion will likely be very common. I don't think it's possible, with the current
regorus
API, to useserde-transcode
(or a similar approach) to perform this conversion efficiently. It might be helpful to add a method to perform this type of transformation.