Skip to content

Instantly share code, notes, and snippets.

@louis030195
Created October 24, 2019 11:35
Show Gist options
  • Save louis030195/6ad426ac56f6864e1321ab1d406ff330 to your computer and use it in GitHub Desktop.
Save louis030195/6ad426ac56f6864e1321ab1d406ff330 to your computer and use it in GitHub Desktop.
#![allow(proc_macro_derive_resolution_fallback)]
pub mod handler;
pub mod repository;
use mongodb::bson;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Cat {
#[serde(rename = "_id")] // Use MongoDB's special primary key field name when serializing
pub id: Option<bson::oid::ObjectId>,
pub name: Option<String>,
pub color: Option<String>,
pub age: Option<i32>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct InsertableCat {
pub name: Option<String>,
pub color: Option<String>,
pub age: Option<i32>,
}
impl InsertableCat {
fn from_cat(cats: Cat) -> InsertableCat {
InsertableCat {
name: cats.name,
color: cats.color,
age: cats.age,
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment