updated serde to version 1.0

This commit is contained in:
debris
2017-07-06 11:36:15 +02:00
parent cc718bb108
commit 61d8f90530
116 changed files with 553 additions and 662 deletions

View File

@@ -381,7 +381,7 @@ usage! {
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Config {
parity: Option<Operating>,
account: Option<Account>,
@@ -401,7 +401,7 @@ struct Config {
stratum: Option<Stratum>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Operating {
mode: Option<String>,
mode_timeout: Option<u64>,
@@ -420,7 +420,7 @@ struct Operating {
no_persistent_txqueue: Option<bool>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Account {
unlock: Option<Vec<String>>,
password: Option<Vec<String>>,
@@ -429,7 +429,7 @@ struct Account {
fast_unlock: Option<bool>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Ui {
force: Option<bool>,
disable: Option<bool>,
@@ -439,7 +439,7 @@ struct Ui {
path: Option<String>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Network {
warp: Option<bool>,
port: Option<u16>,
@@ -458,7 +458,7 @@ struct Network {
no_serve_light: Option<bool>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Rpc {
disable: Option<bool>,
port: Option<u16>,
@@ -469,7 +469,7 @@ struct Rpc {
threads: Option<usize>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Ws {
disable: Option<bool>,
port: Option<u16>,
@@ -479,14 +479,14 @@ struct Ws {
hosts: Option<Vec<String>>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Ipc {
disable: Option<bool>,
path: Option<String>,
apis: Option<Vec<String>>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Dapps {
disable: Option<bool>,
port: Option<u16>,
@@ -498,7 +498,7 @@ struct Dapps {
pass: Option<String>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct SecretStore {
disable: Option<bool>,
self_secret: Option<String>,
@@ -510,7 +510,7 @@ struct SecretStore {
path: Option<String>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Ipfs {
enable: Option<bool>,
port: Option<u16>,
@@ -519,7 +519,7 @@ struct Ipfs {
hosts: Option<Vec<String>>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Mining {
author: Option<String>,
engine_signer: Option<String>,
@@ -547,14 +547,14 @@ struct Mining {
refuse_service_transactions: Option<bool>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Stratum {
interface: Option<String>,
port: Option<u16>,
secret: Option<String>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Footprint {
tracing: Option<String>,
pruning: Option<String>,
@@ -572,17 +572,17 @@ struct Footprint {
num_verifiers: Option<usize>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Snapshots {
disable_periodic: Option<bool>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct VM {
jit: Option<bool>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Deserialize)]
struct Misc {
logging: Option<String>,
log_file: Option<String>,

View File

@@ -55,28 +55,18 @@ macro_rules! usage {
use util::version;
use docopt::{Docopt, Error as DocoptError};
use helpers::replace_home;
use rustc_serialize;
#[derive(Debug)]
pub enum ArgsError {
Docopt(DocoptError),
Parsing(Vec<toml::ParserError>),
Decode(toml::DecodeError),
Decode(toml::de::Error),
Config(String, io::Error),
UnknownFields(String),
}
impl ArgsError {
pub fn exit(self) -> ! {
match self {
ArgsError::Docopt(e) => e.exit(),
ArgsError::Parsing(errors) => {
println_stderr!("There is an error in config file.");
for e in &errors {
println_stderr!("{}", e);
}
process::exit(2)
},
ArgsError::Decode(e) => {
println_stderr!("You might have supplied invalid parameters in config file.");
println_stderr!("{}", e);
@@ -87,21 +77,20 @@ macro_rules! usage {
println_stderr!("{}", e);
process::exit(2)
},
ArgsError::UnknownFields(fields) => {
println_stderr!("You have some extra fields in your config file:");
println_stderr!("{}", fields);
process::exit(2)
}
}
}
}
impl From<DocoptError> for ArgsError {
fn from(e: DocoptError) -> Self { ArgsError::Docopt(e) }
fn from(e: DocoptError) -> Self {
ArgsError::Docopt(e)
}
}
impl From<toml::DecodeError> for ArgsError {
fn from(e: toml::DecodeError) -> Self { ArgsError::Decode(e) }
impl From<toml::de::Error> for ArgsError {
fn from(e: toml::de::Error) -> Self {
ArgsError::Decode(e)
}
}
#[derive(Debug, PartialEq)]
@@ -137,7 +126,7 @@ macro_rules! usage {
}
}
#[derive(Default, Debug, PartialEq, Clone, RustcDecodable)]
#[derive(Default, Debug, PartialEq, Clone, Deserialize)]
struct RawArgs {
$(
$field_a: $typ_a,
@@ -192,20 +181,7 @@ macro_rules! usage {
}
fn parse_config(config: &str) -> Result<Config, ArgsError> {
let mut value_parser = toml::Parser::new(&config);
match value_parser.parse() {
Some(value) => {
let mut decoder = toml::Decoder::new(toml::Value::Table(value));
let result = rustc_serialize::Decodable::decode(&mut decoder);
match (result, decoder.toml) {
(Err(e), _) => Err(e.into()),
(_, Some(toml)) => Err(ArgsError::UnknownFields(toml::encode_str(&toml))),
(Ok(config), None) => Ok(config),
}
},
None => Err(ArgsError::Parsing(value_parser.errors)),
}
Ok(toml::from_str(config)?)
}
pub fn print_version() -> String {
@@ -229,7 +205,7 @@ macro_rules! usage {
}
pub fn parse<S: AsRef<str>>(command: &[S]) -> Result<Self, DocoptError> {
Docopt::new(Self::usage()).and_then(|d| d.argv(command).decode())
Docopt::new(Self::usage()).and_then(|d| d.argv(command).deserialize())
}
fn usage() -> String {