Crate serde_hjson
source · [−]Expand description
What is Hjson?
A configuration file format for humans. Relaxed syntax, fewer mistakes, more comments. See http://hjson.org
Data types that can be encoded are JavaScript types (see the serde_hjson:Value
enum for more
details):
Boolean
: equivalent to rust’sbool
I64
: equivalent to rust’si64
U64
: equivalent to rust’su64
F64
: equivalent to rust’sf64
String
: equivalent to rust’sString
Array
: equivalent to rust’sVec<T>
, but also allowing objects of different types in the same arrayObject
: equivalent to rust’sserde_hjson::Map<String, serde_hjson::Value>
Null
Examples of use
Parsing a str
to Value
and reading the result
//#![feature(custom_derive, plugin)]
//#![plugin(serde_macros)]
extern crate serde_hjson;
use serde_hjson::Value;
fn main() {
let data: Value = serde_hjson::from_str("{foo: 13, bar: \"baz\"}").unwrap();
println!("data: {:?}", data);
println!("object? {}", data.is_object());
let obj = data.as_object().unwrap();
let foo = obj.get("foo").unwrap();
println!("array? {:?}", foo.as_array());
// array? None
println!("u64? {:?}", foo.as_u64());
// u64? Some(13u64)
for (key, value) in obj.iter() {
println!("{}: {}", key, match *value {
Value::U64(v) => format!("{} (u64)", v),
Value::String(ref v) => format!("{} (string)", v),
_ => unreachable!(),
});
}
// bar: baz (string)
// foo: 13 (u64)
}
Re-exports
pub use self::de::Deserializer;
pub use self::de::StreamDeserializer;
pub use self::de::from_iter;
pub use self::de::from_reader;
pub use self::de::from_slice;
pub use self::de::from_str;
pub use self::error::Error;
pub use self::error::ErrorCode;
pub use self::error::Result;
pub use self::ser::Serializer;
pub use self::ser::to_writer;
pub use self::ser::to_vec;
pub use self::ser::to_string;
pub use self::value::Value;
pub use self::value::Map;
pub use self::value::to_value;
pub use self::value::from_value;
Modules
JSON Builders
Hjson Deserialization
JSON Errors
Hjson Serialization
Hjson Value
Macros
Create a function to forward a specific serialize call to the generic deserialize