rust-embedded-community / serde-json-core

`serde-json` for `no_std` programs
Apache License 2.0
161 stars 59 forks source link

serialize_bytes is not unreachable now #51

Closed rfael closed 3 years ago

rfael commented 3 years ago

serialize_bytes can push to output JSON raw bytes now. I now it can produce JSON with invalid data so it should be used with caution. I added this because I need a way to serialize f32 with fixed precision. Example:


pub struct SimpleDecimal(f32);

impl Serialize for SimpleDecimal {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let mut aux: String<U48> = String::new();
        write!(aux, "{:.2}", self.0).unwrap();
        serializer.serialize_bytes(&aux.as_bytes())
    }
}
rfael commented 3 years ago

@eldruin Changelog updated.