Created
September 21, 2019 11:40
-
-
Save rust-play/c25c6397f276be9eff341ea0b9292f3c 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 CreateBuilder { | |
collection: Option<String>, | |
data: String | |
} | |
impl<S: Serialize> From<S> for CreateBuilder { | |
fn from(data: S) -> Self { | |
Self { | |
collection: None, | |
data: serde_json::to_string(&data).unwrap(), | |
} | |
} | |
} | |
impl<S: Serialize> From<(&str, S)> for CreateBuilder { | |
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