1 unstable release
0.1.0 | Apr 17, 2023 |
---|
#11 in #object-id
4KB
serde_with_object_id
This crate provide DisplayFromObjectId
which aims to provide de/serialize of mongodb::bson::oid::ObjectId
using serde_with
and serde
.
Usage
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>,
}
Install
cargo add serde -F derive
cargo add mongodb -F bson-serde_with
cargo add serde_with_object_id
Other links
lib.rs
:
serde_with_object_id
This crate provide DisplayFromObjectId
which aims to provide de/serialize of mongodb::bson::oid::ObjectId
using serde_with
and serde
.
Usage
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use serde_with_object_id::DisplayFromObjectId;
#[serde_as]
#[derive(Deserialize, Serialize)]
pub struct SomeDocument {
#[serde_as(as = "DisplayFromObjectId")]
pub id: String,
#[serde_as(as = "Option<DisplayFromObjectId>")]
pub id_optional: Option<String>,
}
Dependencies
~26–37MB
~689K SLoC