Skip to content

Cow and ValueRef #1260

Open
Open
@BrandonDyer-Disney

Description

@BrandonDyer-Disney

I understand that sometimes serde_json can't guarantee it'll be able to give a &str because the representation may contain escape characters, but we can typically get around this using Cow.

The same way I can do this with a struct:

#[derive(Deserialize)]
struct MyStruct<'a> {
    #[serde(borrow)]
    some_str: Cow<'a, str>,
}

it would be nice to have the same thing for Value.

// Owned
enum Value {
    Null,
    Bool(bool),
    Number(Number),
    String(String),
    Array(Vec<Value>),
    Object(Map<String, Value>),
}

// Borrowed
enum ValueRef<'a> {
    Null,
    Bool(bool),
    Number(Number),
    String(Cow<'a, str>),
    Array(Vec<ValueRef<'a>>),
    Object(Map<Cow<'a, str>, ValueRef<'a>>),
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions