Created
May 31, 2018 22:06
-
-
Save killercup/c3997391e5bcb2834674c9c3e49e2f0c to your computer and use it in GitHub Desktop.
Serde Cows (1 of 3)
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
#[macro_use] extern crate serde_derive; | |
extern crate serde_json; | |
use std::borrow::Cow; | |
#[derive(Debug, Deserialize)] | |
struct Foo<'input> { | |
bar: Cow<'input, str>, | |
} | |
fn main() { | |
let input = r#"{ "bar": "baz" }"#; | |
let foo: Foo = serde_json::from_str(input).unwrap(); | |
match foo.bar { | |
Cow::Borrowed(x) => println!("borrowed {}", x), | |
Cow::Owned(x) => println!("owned {}", x), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment