How can I use Serde with a JSON array with different objects for successes and errors?
问题 I want to use Serde to create an array with error messages as well as proper objects: extern crate serde; // 1.0.70 #[macro_use] extern crate serde_derive; // 1.0.70 extern crate serde_json; // 1.0.24 #[derive(Serialize, Deserialize, Debug)] pub struct MyError { error: String, } #[derive(Serialize, Deserialize, Debug)] pub struct MyAge { age: i32, name: String, } fn get_results(ages: Vec<i32>) -> Vec<MyAge> { let mut results = vec![]; for age in ages { if age < 100 && age > 0 { results.push