Skip to content

Provide From impls  #31

@malobre

Description

@malobre

I'd like to use this crate's serde_value::Value as a more generic version of serde_json::Value.
My use case is an HTTP API where the success response body is defined as such:

#[derive(serde::Serialize)]
struct SuccessBody {
    data: serde_json::Value,
}

impl SuccessBody {
    pub fn new(data: impl Into<serde_json::Value>) -> Self {
        let data = data.into();
        Self { data }
    }
}

Since most (all?) serialize_* are infallible, e.g:

serde-value/src/ser.rs

Lines 77 to 87 in 47190f5

fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error> {
Ok(Value::Bool(v))
}
fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error> {
Ok(Value::I8(v))
}
fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error> {
Ok(Value::I16(v))
}

this should be trivial to implement.

I can submit a PR if you believe this is worth implementing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions