Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Serde Cows (3 of 3)
#[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?\" - \"yeah\"" }"#;
let foo: Foo = serde_json::from_str(input).unwrap();
match {
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