aboutsummaryrefslogtreecommitdiff
path: root/src/toml.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-06-21 23:35:49 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-06-22 22:23:27 -0700
commitf06fae1602e857975ba3b3157ef103d38175c8db (patch)
tree0d29f7f43ea86f62c919a21ff5ea6763830bcb40 /src/toml.rs
parent3bbf216491b01a72398c26689c9ea14a5810adfc (diff)
downloadmilf-rs-f06fae1602e857975ba3b3157ef103d38175c8db.tar.gz
milf-rs-f06fae1602e857975ba3b3157ef103d38175c8db.zip
Implement Encoder/Decoder for libserialize traits
Diffstat (limited to 'src/toml.rs')
-rw-r--r--src/toml.rs35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/toml.rs b/src/toml.rs
index 74a4d36..7c75085 100644
--- a/src/toml.rs
+++ b/src/toml.rs
@@ -18,23 +18,46 @@
//! println!("{}", value);
//! ```
//!
+//! # Conversions
+//!
+//! This library also supports using the standard `Encodable` and `Decodable`
+//! traits with TOML values. This library provides the following conversion
+//! capabilities:
+//!
+//! * `String` => `toml::Value` - via `Parser`
+//! * `toml::Value` => `String` - via `Show`
+//! * `toml::Value` => rust object - via `Decoder`
+//! * rust object => `toml::Value` - via `Encoder`
+//!
+//! Convenience functions for performing multiple conversions at a time are also
+//! provided.
+//!
//! [1]: https://github.com/mojombo/toml
//! [2]: https://github.com/BurntSushi/toml-test
#![crate_type = "lib"]
#![feature(macro_rules)]
#![deny(warnings, missing_doc)]
+#![allow(visible_private_types)]
+
+extern crate serialize;
use std::collections::HashMap;
+use std::from_str::FromStr;
pub use parser::{Parser, Error};
+pub use serialization::{Encoder, encode, encode_str};
+// pub use serialization::{Encoder, encode, encode_str};
+pub use serialization::{Error, NeedsKey, NoValue};
+pub use serialization::{InvalidMapKeyLocation, InvalidMapKeyType};
mod parser;
-#[cfg(test)]
-mod test;
+mod show;
+mod serialization;
+#[cfg(test)] mod test;
/// Representation of a TOML value.
-#[deriving(Show, PartialEq, Clone)]
+#[deriving(PartialEq, Clone)]
#[allow(missing_doc)]
pub enum Value {
String(String),
@@ -120,3 +143,9 @@ impl Value {
match *self { Table(ref s) => Some(s), _ => None }
}
}
+
+impl FromStr for Value {
+ fn from_str(s: &str) -> Option<Value> {
+ Parser::new(s).parse().map(Table)
+ }
+}