Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created September 21, 2019 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/c25c6397f276be9eff341ea0b9292f3c to your computer and use it in GitHub Desktop.
Save rust-play/c25c6397f276be9eff341ea0b9292f3c to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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