serde_with_object_id

Crates.ioserde_with_object_id
lib.rsserde_with_object_id
version0.1.0
sourcesrc
created_at2023-04-17 15:08:20.040434
updated_at2023-04-17 15:08:20.040434
descriptionserde_with_object_id
homepage
repositoryhttps://github.com/susonwaiba/serde_with_object_id
max_upload_size
id841573
size5,061
Suson Waiba (susonwaiba)

documentation

README

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

Commit count: 5

cargo fmt