#serialization #json #no_std

no-std sval_json

Json support for the sval serialization framework

13 releases

✓ Uses Rust 2018 edition

0.2.0 May 10, 2019
0.1.5 May 8, 2019
0.1.4 Apr 30, 2019
0.1.3 Mar 28, 2019
0.0.4 Dec 6, 2018

#92 in #serialization

Download history 5/week @ 2019-01-25 1/week @ 2019-02-01 1/week @ 2019-02-08 2/week @ 2019-02-15 11/week @ 2019-02-22 19/week @ 2019-03-01 3/week @ 2019-03-08 4/week @ 2019-03-15 56/week @ 2019-03-22 3/week @ 2019-03-29 13/week @ 2019-04-05 2/week @ 2019-04-12 10/week @ 2019-04-19 14/week @ 2019-04-26 24/week @ 2019-05-03

55 downloads per month

Apache-2.0 OR MIT

176KB
4.5K SLoC


lib.rs:

JSON support for sval.

This library is no-std, so it can be run in environments that don't have access to an allocator.

Getting started

Add sval_json to your Cargo.toml:

[dependencies.sval_json]
version = "0.2.0"

Writing JSON to fmt::Write

# #[cfg(not(feature = "std"))]
# fn main() {}
# #[cfg(feature = "std")]
# fn main() -> Result<(), Box<std::error::Error>> {
let json = sval_json::to_fmt(MyWrite, 42)?;
# Ok(())
# }
# use std::fmt::{self, Write};
# struct MyWrite;
# impl Write for MyWrite {
#     fn write_str(&mut self, _: &str) -> fmt::Result {
#         Ok(())
#     }
# }

Writing JSON to a String

Add the std feature to your Cargo.toml to enable this module:

[dependencies.sval_json]
features = ["std"]
# #[cfg(not(feature = "std"))]
# fn main() {}
# #[cfg(feature = "std")]
# fn main() -> Result<(), Box<std::error::Error>> {
let json = sval_json::to_string(42)?;
# Ok(())
# }

Writing JSON to a io::Write

# #[cfg(not(feature = "std"))]
# fn main() {}
# #[cfg(feature = "std")]
# fn main() -> Result<(), Box<std::error::Error>> {
# use std::io::{self, Write};
# struct MyWrite;
# impl Write for MyWrite {
#     fn write(&mut self, _: &[u8]) -> io::Result<usize> {
#         Ok(0)
#     }
#     fn flush(&mut self) -> io::Result<()> { Ok(()) }
# }
let json = sval_json::to_writer(MyWrite, 42)?;
# Ok(())
# }

Dependencies

~92KB