Skip to content

Add support for borrowed deserialization #231

@TedDriggs

Description

@TedDriggs

I have a struct like this:

#[derive(Deserialize)]
struct Example<'a> {
    #[serde(borrow)]
    field: Option<Cow<'a, str>>,
    #[serde(borrow, default)]
    other_field: Vec<Cow<'a, str>>,
}

I'd like to use it with this crate, but the DeserializeOwned bound gets in the way.

I think the issue is that deserialization goes through Document, which in turn requires ownership of strings etc. inside it. Is that correct, and if so could that be mitigated by having a bson::borrow::Bson which points into a backing &'a [u8]?

Metadata

Metadata

Assignees

No one assigned

    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