commit
07874c7f94
24
src/lib.rs
24
src/lib.rs
|
@ -2,8 +2,8 @@
|
||||||
//!
|
//!
|
||||||
//! [TOML]: https://github.com/toml-lang/toml
|
//! [TOML]: https://github.com/toml-lang/toml
|
||||||
//!
|
//!
|
||||||
//! This library implements a [TOML] v0.4.0 compatible parser. This crate also
|
//! This library implements a [TOML] v0.4.0 compatible parser,
|
||||||
//! primarily supports the [`serde`] library for encoding/decoding support to
|
//! primarily supporting the [`serde`] library for encoding/decoding
|
||||||
//! various types in Rust.
|
//! various types in Rust.
|
||||||
//!
|
//!
|
||||||
//! TOML itself is a simple, ergonomic, and readable configuration format:
|
//! TOML itself is a simple, ergonomic, and readable configuration format:
|
||||||
|
@ -37,8 +37,8 @@
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! You'll note that TOML is very similar to JSON with the notable addition of a
|
//! TOML is similar to JSON with the notable addition of a `Datetime`
|
||||||
//! `Datetime` type. In general TOML and JSON are interchangeable in terms of
|
//! type. In general, TOML and JSON are interchangeable in terms of
|
||||||
//! formats.
|
//! formats.
|
||||||
//!
|
//!
|
||||||
//! ## Parsing TOML
|
//! ## Parsing TOML
|
||||||
|
@ -53,26 +53,26 @@
|
||||||
//! assert_eq!(value["foo"].as_str(), Some("bar"));
|
//! assert_eq!(value["foo"].as_str(), Some("bar"));
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! The `Value` type implements a number of convenience methods and traits,
|
//! The `Value` type implements a number of convenience methods and
|
||||||
//! where the example above is using `FromStr` to parse a `str` into a `Value`.
|
//! traits; the example above uses `FromStr` to parse a `str` into a
|
||||||
|
//! `Value`.
|
||||||
//!
|
//!
|
||||||
//! ## Deserialization and Serialization
|
//! ## Deserialization and Serialization
|
||||||
//!
|
//!
|
||||||
//! This crate currently supports [`serde`] 0.9 with a number of
|
//! This crate supports [`serde`] 0.9 with a number of
|
||||||
//! implementations of the `Deserialize`, `Serialize`, `Deserializer`, and
|
//! implementations of the `Deserialize`, `Serialize`, `Deserializer`, and
|
||||||
//! `Serializer` traits. Namely, you'll find in this crate:
|
//! `Serializer` traits. Namely, you'll find:
|
||||||
//!
|
//!
|
||||||
//! * `Deserialize for Value`
|
//! * `Deserialize for Value`
|
||||||
//! * `Serialize for Value`
|
//! * `Serialize for Value`
|
||||||
//! * `Deserialize for Datetime`
|
//! * `Deserialize for Datetime`
|
||||||
//! * `Serialize for Datetime`
|
//! * `Serialize for Datetime`
|
||||||
//!
|
|
||||||
//! * `Deserializer for de::Deserializer`
|
//! * `Deserializer for de::Deserializer`
|
||||||
//! * `Serializer for ser::Serializer`
|
//! * `Serializer for ser::Serializer`
|
||||||
//! * `Deserializer for Value`
|
//! * `Deserializer for Value`
|
||||||
//!
|
//!
|
||||||
//! This notably means that you can use Serde to deserialize/serialize the
|
//! This means that you can use Serde to deserialize/serialize the
|
||||||
//! `Value` type as well as the `Datetime` type in this crate. Similarly you can
|
//! `Value` type as well as the `Datetime` type in this crate. You can also
|
||||||
//! use the `Deserializer`, `Serializer`, or `Value` type itself to act as
|
//! use the `Deserializer`, `Serializer`, or `Value` type itself to act as
|
||||||
//! a deserializer/serializer for arbitrary types.
|
//! a deserializer/serializer for arbitrary types.
|
||||||
//!
|
//!
|
||||||
|
@ -112,7 +112,7 @@
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! Similarly you can serialize types in a similar fashion:
|
//! You can serialize types in a similar fashion:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! #[macro_use]
|
//! #[macro_use]
|
||||||
|
|
|
@ -103,7 +103,7 @@ impl Value {
|
||||||
match *self { Value::Float(f) => Some(f), _ => None }
|
match *self { Value::Float(f) => Some(f), _ => None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tests whether this value is an float
|
/// Tests whether this value is a float
|
||||||
pub fn is_float(&self) -> bool {
|
pub fn is_float(&self) -> bool {
|
||||||
self.as_float().is_some()
|
self.as_float().is_some()
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ impl Value {
|
||||||
match *self { Value::Boolean(b) => Some(b), _ => None }
|
match *self { Value::Boolean(b) => Some(b), _ => None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tests whether this value is an boolg
|
/// Tests whether this value is a boolean
|
||||||
pub fn is_bool(&self) -> bool {
|
pub fn is_bool(&self) -> bool {
|
||||||
self.as_bool().is_some()
|
self.as_bool().is_some()
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ impl Value {
|
||||||
match *self { Value::Datetime(ref s) => Some(s), _ => None }
|
match *self { Value::Datetime(ref s) => Some(s), _ => None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tests whether this value is an datetime
|
/// Tests whether this value is a datetime
|
||||||
pub fn is_datetime(&self) -> bool {
|
pub fn is_datetime(&self) -> bool {
|
||||||
self.as_datetime().is_some()
|
self.as_datetime().is_some()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue