mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-01-06 19:45:20 +01:00
fix(serde): update to latest serde/rust
This commit is contained in:
@@ -29,8 +29,8 @@ name = "${util.program_name()}"
|
||||
hyper = ">= 0.6.8"
|
||||
## Must match the one hyper uses, otherwise there are duplicate similarly named `Mime` structs
|
||||
mime = "0.1.0"
|
||||
serde = ">= 0.5.0"
|
||||
serde_json = "*"
|
||||
serde = ">= 0.6.0"
|
||||
serde_json = ">= 0.6.0"
|
||||
yup-oauth2 = "*"
|
||||
% for dep in cargo.get('dependencies', list()):
|
||||
${dep}
|
||||
|
||||
@@ -118,7 +118,7 @@ pub struct FieldCursor(Vec<String>);
|
||||
|
||||
impl ToString for FieldCursor {
|
||||
fn to_string(&self) -> String {
|
||||
self.0.connect(".")
|
||||
self.0.join(".")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,15 +235,15 @@ impl FieldCursor {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_json_value(&self, mut object: &mut Value,
|
||||
pub fn set_json_value(&self, mut object: &mut Value,
|
||||
value: &str, type_info: JsonTypeInfo,
|
||||
err: &mut InvalidOptionsError,
|
||||
err: &mut InvalidOptionsError,
|
||||
orig_cursor: &FieldCursor) {
|
||||
assert!(self.0.len() > 0);
|
||||
|
||||
for field in &self.0[..self.0.len()-1] {
|
||||
let tmp = object;
|
||||
object =
|
||||
object =
|
||||
match *tmp {
|
||||
Value::Object(ref mut mapping) => {
|
||||
mapping.entry(field.to_owned()).or_insert(
|
||||
@@ -257,19 +257,19 @@ impl FieldCursor {
|
||||
match *object {
|
||||
Value::Object(ref mut mapping) => {
|
||||
let field = &self.0[self.0.len()-1];
|
||||
let to_jval =
|
||||
|value: &str, jtype: JsonType, err: &mut InvalidOptionsError|
|
||||
let to_jval =
|
||||
|value: &str, jtype: JsonType, err: &mut InvalidOptionsError|
|
||||
-> Value {
|
||||
match jtype {
|
||||
JsonType::Boolean =>
|
||||
JsonType::Boolean =>
|
||||
Value::Bool(arg_from_str(value, err, &field, "boolean")),
|
||||
JsonType::Int =>
|
||||
JsonType::Int =>
|
||||
Value::I64(arg_from_str(value, err, &field, "int")),
|
||||
JsonType::Uint =>
|
||||
JsonType::Uint =>
|
||||
Value::U64(arg_from_str(value, err, &field, "uint")),
|
||||
JsonType::Float =>
|
||||
JsonType::Float =>
|
||||
Value::F64(arg_from_str(value, err, &field, "float")),
|
||||
JsonType::String =>
|
||||
JsonType::String =>
|
||||
Value::String(value.to_owned()),
|
||||
}
|
||||
};
|
||||
@@ -336,7 +336,7 @@ pub fn calltype_from_str(name: &str, valid_protocols: Vec<String>, err: &mut Inv
|
||||
match UploadProtocol::from_str(name) {
|
||||
Ok(up) => up,
|
||||
Err(msg) => {
|
||||
err.issues.push(CLIError::InvalidUploadProtocol(name.to_string(), valid_protocols));
|
||||
err.issues.push(CLIError::InvalidUploadProtocol(name.to_string(), valid_protocols));
|
||||
UploadProtocol::Simple
|
||||
}
|
||||
})
|
||||
@@ -374,8 +374,8 @@ pub fn writer_from_opts(arg: Option<&str>) -> Result<Box<Write>, io::Error> {
|
||||
}
|
||||
|
||||
|
||||
pub fn arg_from_str<'a, T>(arg: &str, err: &mut InvalidOptionsError,
|
||||
arg_name: &'a str,
|
||||
pub fn arg_from_str<'a, T>(arg: &str, err: &mut InvalidOptionsError,
|
||||
arg_name: &'a str,
|
||||
arg_type: &'a str) -> T
|
||||
where T: FromStr + Default,
|
||||
<T as FromStr>::Err: fmt::Display {
|
||||
@@ -409,7 +409,7 @@ impl TokenStorage for JsonTokenStorage {
|
||||
match token {
|
||||
None => {
|
||||
match fs::remove_file(self.path(scope_hash)) {
|
||||
Err(err) =>
|
||||
Err(err) =>
|
||||
match err.kind() {
|
||||
io::ErrorKind::NotFound => Ok(()),
|
||||
_ => Err(json::Error::IoError(err))
|
||||
@@ -422,7 +422,7 @@ impl TokenStorage for JsonTokenStorage {
|
||||
Ok(mut f) => {
|
||||
match json::to_writer_pretty(&mut f, &token) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(io_err) => Err(json::Error::IoError(io_err)),
|
||||
Err(serde_err) => Err(serde_err),
|
||||
}
|
||||
},
|
||||
Err(io_err) => Err(json::Error::IoError(io_err))
|
||||
@@ -453,17 +453,17 @@ impl TokenStorage for JsonTokenStorage {
|
||||
#[derive(Debug)]
|
||||
pub enum ApplicationSecretError {
|
||||
DecoderError((String, json::Error)),
|
||||
FormatError(String),
|
||||
FormatError(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for ApplicationSecretError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
ApplicationSecretError::DecoderError((ref path, ref err))
|
||||
=> writeln!(f, "Could not decode file at '{}' with error: {}.",
|
||||
=> writeln!(f, "Could not decode file at '{}' with error: {}.",
|
||||
path, err),
|
||||
ApplicationSecretError::FormatError(ref path)
|
||||
=> writeln!(f, "'installed' field is unset in secret file at '{}'.",
|
||||
=> writeln!(f, "'installed' field is unset in secret file at '{}'.",
|
||||
path),
|
||||
}
|
||||
}
|
||||
@@ -483,7 +483,7 @@ impl fmt::Display for ConfigurationError {
|
||||
match *self {
|
||||
ConfigurationError::DirectoryCreationFailed((ref dir, ref err))
|
||||
=> writeln!(f, "Directory '{}' could not be created with error: {}.", dir, err),
|
||||
ConfigurationError::DirectoryUnset
|
||||
ConfigurationError::DirectoryUnset
|
||||
=> writeln!(f, "--config-dir was unset or empty."),
|
||||
ConfigurationError::HomeExpansionFailed(ref dir)
|
||||
=> writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'.", dir),
|
||||
@@ -530,10 +530,10 @@ impl fmt::Display for FieldError {
|
||||
FieldError::TrailingFieldSep(ref field)
|
||||
=> writeln!(f, "'{}': Single field separator may not be last character.", field),
|
||||
FieldError::Unknown(ref field, ref suggestion, ref value) => {
|
||||
let suffix =
|
||||
let suffix =
|
||||
match *suggestion {
|
||||
Some(ref s) => {
|
||||
let kv =
|
||||
let kv =
|
||||
match *value {
|
||||
Some(ref v) => format!("{}={}", s, v),
|
||||
None => s.clone(),
|
||||
@@ -544,7 +544,7 @@ impl fmt::Display for FieldError {
|
||||
};
|
||||
writeln!(f, "Field '{}' does not exist.{}", field, suffix)
|
||||
},
|
||||
FieldError::Duplicate(ref cursor)
|
||||
FieldError::Duplicate(ref cursor)
|
||||
=> writeln!(f, "Value at '{}' was already set", cursor),
|
||||
FieldError::Empty
|
||||
=> writeln!(f, "Field names must not be empty."),
|
||||
@@ -572,13 +572,13 @@ impl fmt::Display for CLIError {
|
||||
CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err),
|
||||
CLIError::Input(ref err) => write!(f, "Input -> {}", err),
|
||||
CLIError::Field(ref err) => write!(f, "Field -> {}", err),
|
||||
CLIError::InvalidUploadProtocol(ref proto_name, ref valid_names)
|
||||
=> writeln!(f, "'{}' is not a valid upload protocol. Choose from one of {}.", proto_name, valid_names.connect(", ")),
|
||||
CLIError::ParseError(ref arg_name, ref type_name, ref value, ref err_desc)
|
||||
CLIError::InvalidUploadProtocol(ref proto_name, ref valid_names)
|
||||
=> writeln!(f, "'{}' is not a valid upload protocol. Choose from one of {}.", proto_name, valid_names.join(", ")),
|
||||
CLIError::ParseError(ref arg_name, ref type_name, ref value, ref err_desc)
|
||||
=> writeln!(f, "Failed to parse argument '{}' with value '{}' as {} with error: {}.",
|
||||
arg_name, value, type_name, err_desc),
|
||||
CLIError::UnknownParameter(ref param_name, ref possible_values) => {
|
||||
let mut suffix =
|
||||
let mut suffix =
|
||||
match did_you_mean(param_name, &possible_values) {
|
||||
Some(v) => format!(" Did you mean '{}' ?", v),
|
||||
None => String::new(),
|
||||
@@ -632,7 +632,7 @@ pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> {
|
||||
return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset))
|
||||
}
|
||||
|
||||
let expanded_config_dir =
|
||||
let expanded_config_dir =
|
||||
if trdir.as_bytes()[0] == b'~' {
|
||||
match env::var("HOME").ok().or(env::var("UserProfile").ok()) {
|
||||
None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))),
|
||||
@@ -655,8 +655,8 @@ pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> {
|
||||
Ok(expanded_config_dir)
|
||||
}
|
||||
|
||||
pub fn application_secret_from_directory(dir: &str,
|
||||
secret_basename: &str,
|
||||
pub fn application_secret_from_directory(dir: &str,
|
||||
secret_basename: &str,
|
||||
json_console_secret: &str)
|
||||
-> Result<ApplicationSecret, CLIError> {
|
||||
let secret_path = Path::new(dir).join(secret_basename);
|
||||
@@ -677,10 +677,13 @@ pub fn application_secret_from_directory(dir: &str,
|
||||
Err(cfe) => cfe,
|
||||
Ok(mut f) => {
|
||||
// Assure we convert 'ugly' json string into pretty one
|
||||
let console_secret: ConsoleApplicationSecret
|
||||
let console_secret: ConsoleApplicationSecret
|
||||
= json::from_str(json_console_secret).unwrap();
|
||||
match json::to_writer_pretty(&mut f, &console_secret) {
|
||||
Err(io_err) => io_err,
|
||||
Err(serde_err) => match serde_err {
|
||||
json::Error::IoError(err) => err,
|
||||
_ => panic!("Unexpected serde error: {:#?}", serde_err)
|
||||
},
|
||||
Ok(_) => continue,
|
||||
}
|
||||
}
|
||||
@@ -691,15 +694,15 @@ pub fn application_secret_from_directory(dir: &str,
|
||||
},
|
||||
Ok(mut f) => {
|
||||
match json::de::from_reader::<_, ConsoleApplicationSecret>(f) {
|
||||
Err(json::Error::IoError(err)) =>
|
||||
Err(json::Error::IoError(err)) =>
|
||||
return secret_io_error(err),
|
||||
Err(json_err) =>
|
||||
Err(json_err) =>
|
||||
return Err(CLIError::Configuration(
|
||||
ConfigurationError::Secret(
|
||||
ApplicationSecretError::DecoderError(
|
||||
(secret_str(), json_err)
|
||||
)))),
|
||||
Ok(console_secret) =>
|
||||
Ok(console_secret) =>
|
||||
match console_secret.installed {
|
||||
Some(secret) => return Ok(secret),
|
||||
None => return Err(
|
||||
@@ -713,4 +716,4 @@ pub fn application_secret_from_directory(dir: &str,
|
||||
}
|
||||
}
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user