Created
September 21, 2019 11:41
-
-
Save rust-play/653cf1c553b1514ce1550f6ced22cca0 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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::Serialize; | |
pub struct CreateData { | |
collection: Option<String>, | |
data: String | |
} | |
impl<S: Serialize> From<S> for CreateData { | |
fn from(data: S) -> Self { | |
Self { | |
collection: None, | |
data: serde_json::to_string(&data).unwrap(), | |
} | |
} | |
} | |
impl<S: Serialize> From<(&str, S)> for CreateData { | |
fn from((collection, data): (&str, S)) -> Self { | |
Self { | |
collection: Some(collection.to_string()), | |
data: serde_json::to_string(&data).unwrap(), | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment