diff --git a/Cargo.toml b/Cargo.toml index 238d1a0..1c096a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,8 +18,14 @@ encode = ["encoding"] ssl = ["openssl"] nochanlists = [] -[dependencies.rustc-serialize] -version = "0.3" +[dependencies.serde] +version = "1.0.8" + +[dependencies.serde_json] +version = "1.0.2" + +[dependencies.serde_derive] +version = "1.0.8" [dependencies.time] version = "0.1" diff --git a/src/client/data/config.rs b/src/client/data/config.rs index cb32c73..1780082 100644 --- a/src/client/data/config.rs +++ b/src/client/data/config.rs @@ -1,14 +1,14 @@ -//! JSON configuration files using libserialize. +//! JSON configuration files using serde use std::borrow::ToOwned; use std::collections::HashMap; use std::fs::File; use std::io::prelude::*; use std::io::{Error, ErrorKind, Result}; use std::path::Path; -use rustc_serialize::json::{decode, encode}; +use serde_json; /// Configuration data. -#[derive(Clone, RustcDecodable, RustcEncodable, Default, PartialEq, Debug)] +#[derive(Clone, Deserialize, Serialize, Default, PartialEq, Debug)] pub struct Config { /// A list of the owners of the client by nickname (for bots). pub owners: Option>, @@ -66,7 +66,7 @@ impl Config { let mut file = try!(File::open(path)); let mut data = String::new(); try!(file.read_to_string(&mut data)); - decode(&data[..]).map_err(|_| + serde_json::from_str(&data[..]).map_err(|_| Error::new(ErrorKind::InvalidInput, "Failed to decode configuration file.") ) } @@ -74,7 +74,7 @@ impl Config { /// Saves a JSON configuration to the desired path. pub fn save>(&self, path: P) -> Result<()> { let mut file = try!(File::create(path)); - file.write_all(try!(encode(self).map_err(|_| + file.write_all(try!(serde_json::to_string(self).map_err(|_| Error::new(ErrorKind::InvalidInput, "Failed to encode configuration file.") )).as_bytes()) } diff --git a/src/lib.rs b/src/lib.rs index a74270b..624e829 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,9 @@ extern crate time; #[cfg(feature = "encode")] extern crate encoding; -extern crate rustc_serialize; +extern crate serde; +#[macro_use] extern crate serde_derive; +extern crate serde_json; #[cfg(feature = "ssl")] extern crate openssl; pub mod client;