Skip to content

Can't serialize/deserialize struct which contains Option<chrono::DateTime<Utc>> field. #303

Closed
@WindSoilder

Description

@WindSoilder

Take the following struct as example:

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Debug, Serialize, Deserialize)]
pub struct Authorization {
    #[serde(with = "bson::serde_helpers::uuid_as_binary")]
    client_id: Uuid,
    dbs: Vec<String>,
    colls: Option<Vec<String>>,
    #[serde(with = "bson::serde_helpers::chrono_datetime_as_bson_datetime")]
    start_date: Option<DateTime<Utc>>,
    #[serde(with = "bson::serde_helpers::chrono_datetime_as_bson_datetime")]
    end_date: Option<DateTime<Utc>>,
    name: String,
}

When I try to complile, I get the following error message:

mismatched types
= note: expected reference `&chrono::DateTime<Utc>`
              found reference `&'__a std::option::Option<chrono::DateTime<Utc>>`

I think this should work for start_date and end_date field just like colls field in the given Authorization struct, sorry for that I go through documentation and can't find out an answer, am I miss something?

Metadata

Metadata

Assignees

Labels

tracked-in-jiraTicket filed in Mongo's Jira system

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions