Crates.io | serde_with_object_id |
lib.rs | serde_with_object_id |
version | 0.1.0 |
source | src |
created_at | 2023-04-17 15:08:20.040434 |
updated_at | 2023-04-17 15:08:20.040434 |
description | serde_with_object_id |
homepage | |
repository | https://github.com/susonwaiba/serde_with_object_id |
max_upload_size | |
id | 841573 |
size | 5,061 |
This crate provide DisplayFromObjectId
which aims to provide de/serialize of mongodb::bson::oid::ObjectId
using serde_with
and serde
.
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use serde_with_object_id::DisplayFromObjectId;
#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SomeDocument {
#[serde_as(as = "DisplayFromObjectId")]
#[serde(rename = "_id")]
pub id: String,
#[serde_as(as = "Option<DisplayFromObjectId>")]
pub id_optional: Option<String>,
}
cargo add serde -F derive
cargo add mongodb -F bson-serde_with
cargo add serde_with_object_id