Replace rustc-serialize with serde
rustc-serialize is deprecated. Fixes #84.
This commit is contained in:
parent
310c85f336
commit
e33248f043
3 changed files with 16 additions and 8 deletions
10
Cargo.toml
10
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"
|
||||
|
|
|
@ -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<Vec<String>>,
|
||||
|
@ -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<P: AsRef<Path>>(&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())
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue