1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//! # What is Hjson?
//!
//! A configuration file format for humans. Relaxed syntax, fewer mistakes, more comments.
//! See https://hjson.github.io
//!
//! Data types that can be encoded are JavaScript types (see the `serde_hjson:Value` enum for more
//! details):
//!
//! * `Boolean`: equivalent to rust's `bool`
//! * `I64`: equivalent to rust's `i64`
//! * `U64`: equivalent to rust's `u64`
//! * `F64`: equivalent to rust's `f64`
//! * `String`: equivalent to rust's `String`
//! * `Array`: equivalent to rust's `Vec<T>`, but also allowing objects of different types in the
//!    same array
//! * `Object`: equivalent to rust's `serde_hjson::Map<String, serde_hjson::Value>`
//! * `Null`
//!
//! # Sample
//!
//! ```ignore
//! {
//!     FirstName: John
//!     LastName: Doe
//!     Age: 43
//!     Address: {
//!         Street: Downing Street 10
//!         City: London
//!         Country: Great Britain
//!     }
//!     PhoneNumbers: [
//!         +44 1234567
//!         +44 2345678
//!     ]
//! }
//! ```
//!
//! If we assume that FirstName is optional and all other fields are mandatory, the above Hjson could
//! correspond to the following Rust structs:
//!
//! ```ignore
//! #[derive(Serialize, Deserialize)]
//! struct Data {
//!     #[serde(rename="FirstName")] // to comply with Rust coding standards
//!     first_name: Option<String>,
//!     LastName: String,
//!     Age: u32,
//!     Address: Address,
//!     PhoneNumbers: Vec<String>
//! }
//!
//! #[derive(Serialize, Deserialize)]
//! struct Address {
//!     Street: String,
//!     City: String,
//!     Country: String
//! }
//! ```
//!
//! # Type-based Serialization and Deserialization
//!
//! Serde provides a mechanism for low boilerplate serialization & deserialization of values to and
//! from Hjson via the serialization API.  To be able to serialize a piece of data, it must implement
//! the `serde::Serialize` trait.  To be able to deserialize a piece of data, it must implement the
//! `serde::Deserialize` trait.  Serde provides provides an annotation to automatically generate
//! the code for these traits: `#[derive(Serialize, Deserialize)]`.
//!
//! The Hjson API also provides an enum `serde_hjson::Value` and a method `to_value` to serialize
//! objects.  A `serde_hjson::Value` value can be serialized as a string or buffer using the
//! functions described above.
//!
//! # Examples of use
//!
//! ## Parsing a `str` to `Value` and reading the result
//!
//! ```rust
//! //#![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),
//!             _ => format!("other")
//!         });
//!     }
//!     // bar: baz (string)
//!     // foo: 13 (u64)
//! }
//! ```

#![cfg_attr(feature = "nightly-testing", plugin(clippy))]
#![deny(missing_docs)]

#[macro_use] extern crate lazy_static;

extern crate core;
extern crate linked_hash_map;
extern crate num_traits;
extern crate regex;
extern crate serde;

pub use self::de::{
    Deserializer,
    StreamDeserializer,
    from_iter,
    from_reader,
    from_slice,
    from_str,
};
pub use self::error::{Error, ErrorCode, Result};
pub use self::ser::{
    Serializer,
    to_writer,
    to_vec,
    to_string,
};
pub use self::value::{Value, Map, to_value, from_value};

#[macro_use]
mod forward;

pub mod builder;
pub mod de;
pub mod error;
pub mod ser;
mod util;
pub mod value;