diff options
| author | Edward Barnard | 2015-08-29 13:44:52 +0700 |
|---|---|---|
| committer | Edward Barnard | 2015-08-29 13:44:52 +0700 |
| commit | b27c11186b48a5ca0dc16e1e44edfd1fc2252f1f (patch) | |
| tree | 8fb4cd256d8a80fcc9f779f3c532521ced3bfcf6 /src | |
| parent | 890a2ad9aeee6ede065f33b1b346f2d368b00129 (diff) | |
| download | rust-plist-b27c11186b48a5ca0dc16e1e44edfd1fc2252f1f.tar.bz2 | |
Add into_json
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -27,6 +27,25 @@ pub enum Plist { Integer(i64), String(String) } + +use rustc_serialize::base64::{STANDARD, ToBase64}; +use rustc_serialize::json::Json; + +impl Plist { + pub fn into_json(self) -> Json { + match self { + // TODO: Change to map_in_place once stable + Plist::Array(value) => Json::Array(value.into_iter().map(|p| p.into_json()).collect()), + Plist::Dictionary(value) => Json::Object(value.into_iter().map(|(k, v)| (k, v.into_json())).collect()), + Plist::Boolean(value) => Json::Boolean(value), + Plist::Data(value) => Json::String(value.to_base64(STANDARD)), + Plist::Date(value) => Json::String(value.to_rfc3339()), + Plist::Real(value) => Json::F64(value), + Plist::Integer(value) => Json::I64(value), + Plist::String(value) => Json::String(value), + } + } +} #[derive(Clone, Debug, PartialEq)] pub enum PlistEvent { |
