arcnmx / serde-value

Serialization value trees
http://arcnmx.github.io/serde-value/serde_value/
MIT License
43 stars 30 forks source link

Provide `From` impls #31

Open malobre opened 3 years ago

malobre commented 3 years ago

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: https://github.com/arcnmx/serde-value/blob/47190f5a90c0fee90b6e819284801fe7be1df8c3/src/ser.rs#L77-L87 this should be trivial to implement.

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