Created
January 30, 2025 21:57
-
-
Save Stebalien/d10ea54954d822df0d35ab13bd4acff2 to your computer and use it in GitHub Desktop.
trailing.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use serde::{Deserialize, Serialize}; | |
#[derive(Serialize, Deserialize, Debug)] | |
struct Tripple(u32, u32, u32); | |
#[derive(Serialize, Deserialize, Debug)] | |
struct Pair(u32, u32); | |
#[derive(Serialize, Deserialize, Debug)] | |
struct OuterStruct<I> { | |
tuple: I, | |
rest: String, | |
} | |
fn main() { | |
let input = OuterStruct { | |
tuple: Tripple(1, 2, 3), | |
rest: "foo".into(), | |
}; | |
// Serialize a tuple with 3 numbers. | |
let my_json = serde_json::to_string(&input).unwrap(); | |
println!("json: {}", my_json); | |
// Deserialize into a tuple struct with 2 fields. | |
let output: OuterStruct<Pair> = serde_json::from_str(&my_json).unwrap(); | |
println!("{:?}", output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment