Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide From impls #31

Open
malobre opened this issue Jun 25, 2021 · 0 comments
Open

Provide From impls #31

malobre opened this issue Jun 25, 2021 · 0 comments

Comments

@malobre
Copy link

malobre commented Jun 25, 2021

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.

@malobre malobre changed the title Provide From impls for Provide From impls Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant