I'm trying to parse a piece of json string using serde_json
in Rust. I want to match the result of the parse using the following syntax:
match serde_json::from_str(msg.to_text().unwrap()) {
Ok(result) => {
println!("Parsed: {}", response.text);
}
Err(error) => {
println!("Failed to parse: {}", error);
}
}
but the compiler complains to me that he doesn't know the type of the result
and of course, he is right. But how can I tell him the type of the result
? I tried the following code, but it didn't work either. So I want to express the type of variable in the match arm.
match serde_json::from_str(msg.to_text().unwrap()) {
Ok(result: Response) => {
println!("Parsed: {}", response.text);
}
Err(error) => {
println!("Failed to parse: {}, {}", error, msg.to_text.unwrap());
}
}