Encoding with ard/encode
The ard/encode module provides a focused JSON encoder for primitive values. It exposes a small Encodable trait implemented only by the core primitives.
use ard/encodeuse ard/io
fn main() { io::print(encode::json("hello").expect("")) // "hello" io::print(encode::json(42).expect("")) // 42 io::print(encode::json(3.14).expect("")) // 3.14 io::print(encode::json(true).expect("")) // true}trait Encodable
Section titled “trait Encodable”The trait required by the encoder. It is implemented only by the primitive types.
trait Encodable { fn to_dyn() Dynamic}fn json(value: Encodable) Str!Str
Section titled “fn json(value: Encodable) Str!Str”Encode a primitive value as a JSON string. Returns Ok with the JSON string or Err with an error message.
use ard/encode
let json = encode::json(200).expect("Failed to encode")