Expand description
A serialization/deserialization library for Simplified JSON, the Bitsquid/Stingray flavor of JSON.
§Usage
§Serializing
use serde::Serialize;
use serde_sjson::Result;
#[derive(Serialize)]
struct Person {
name: String,
age: u8,
friends: Vec<String>,
}
fn main() -> Result<()> {
let data = Person {
name: String::from("Marc"),
age: 21,
friends: vec![String::from("Jessica"), String::from("Paul")],
};
let s = serde_sjson::to_string(&data)?;
println!("{}", s);
Ok(())
}§Deserializing
use serde::Deserialize;
use serde_sjson::Result;
#[derive(Deserialize)]
struct Person {
name: String,
age: u8,
friends: Vec<String>,
}
fn main() -> Result<()> {
let sjson = r#"
name = Marc
age = 21
friends = [
Jessica
Paul
]"#;
let data: Person = serde_sjson::from_str(sjson)?;
println!(
"{} is {} years old and has {} friends.",
data.name,
data.age,
data.friends.len()
);
Ok(())
}Structs§
- Deserializer
- A container for deserializing Rust values from SJSON.
- Error
- A type encapsulating the different errors that might occurr during serialization or deserialization.
- Serializer
- A container for serializing Rust values into SJSON.
Functions§
- from_
str - Deserializes an SJSON string to a Rust value.
- to_
string - Serializes a value into a string.
- to_vec
- Serializes a value into a byte vector.
- to_
writer - Serializes a value into a generic
io::Write.
Type Aliases§
- Result
- An alias for a
Resultwithserde_sjson::Error.