Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8dab8c0

Browse files
committed
fix(serde): update to latest serde/rust
1 parent 7754a16 commit 8dab8c0

2 files changed

Lines changed: 41 additions & 38 deletions

File tree

src/mako/Cargo.toml.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ name = "${util.program_name()}"
2929
hyper = ">= 0.6.8"
3030
## Must match the one hyper uses, otherwise there are duplicate similarly named `Mime` structs
3131
mime = "0.1.0"
32-
serde = ">= 0.5.0"
33-
serde_json = "*"
32+
serde = ">= 0.6.0"
33+
serde_json = ">= 0.6.0"
3434
yup-oauth2 = "*"
3535
% for dep in cargo.get('dependencies', list()):
3636
${dep}

src/rust/cli/cmn.rs

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub struct FieldCursor(Vec<String>);
118118

119119
impl ToString for FieldCursor {
120120
fn to_string(&self) -> String {
121-
self.0.connect(".")
121+
self.0.join(".")
122122
}
123123
}
124124

@@ -235,15 +235,15 @@ impl FieldCursor {
235235
}
236236
}
237237

238-
pub fn set_json_value(&self, mut object: &mut Value,
238+
pub fn set_json_value(&self, mut object: &mut Value,
239239
value: &str, type_info: JsonTypeInfo,
240-
err: &mut InvalidOptionsError,
240+
err: &mut InvalidOptionsError,
241241
orig_cursor: &FieldCursor) {
242242
assert!(self.0.len() > 0);
243243

244244
for field in &self.0[..self.0.len()-1] {
245245
let tmp = object;
246-
object =
246+
object =
247247
match *tmp {
248248
Value::Object(ref mut mapping) => {
249249
mapping.entry(field.to_owned()).or_insert(
@@ -257,19 +257,19 @@ impl FieldCursor {
257257
match *object {
258258
Value::Object(ref mut mapping) => {
259259
let field = &self.0[self.0.len()-1];
260-
let to_jval =
261-
|value: &str, jtype: JsonType, err: &mut InvalidOptionsError|
260+
let to_jval =
261+
|value: &str, jtype: JsonType, err: &mut InvalidOptionsError|
262262
-> Value {
263263
match jtype {
264-
JsonType::Boolean =>
264+
JsonType::Boolean =>
265265
Value::Bool(arg_from_str(value, err, &field, "boolean")),
266-
JsonType::Int =>
266+
JsonType::Int =>
267267
Value::I64(arg_from_str(value, err, &field, "int")),
268-
JsonType::Uint =>
268+
JsonType::Uint =>
269269
Value::U64(arg_from_str(value, err, &field, "uint")),
270-
JsonType::Float =>
270+
JsonType::Float =>
271271
Value::F64(arg_from_str(value, err, &field, "float")),
272-
JsonType::String =>
272+
JsonType::String =>
273273
Value::String(value.to_owned()),
274274
}
275275
};
@@ -336,7 +336,7 @@ pub fn calltype_from_str(name: &str, valid_protocols: Vec<String>, err: &mut Inv
336336
match UploadProtocol::from_str(name) {
337337
Ok(up) => up,
338338
Err(msg) => {
339-
err.issues.push(CLIError::InvalidUploadProtocol(name.to_string(), valid_protocols));
339+
err.issues.push(CLIError::InvalidUploadProtocol(name.to_string(), valid_protocols));
340340
UploadProtocol::Simple
341341
}
342342
})
@@ -374,8 +374,8 @@ pub fn writer_from_opts(arg: Option<&str>) -> Result<Box<Write>, io::Error> {
374374
}
375375

376376

377-
pub fn arg_from_str<'a, T>(arg: &str, err: &mut InvalidOptionsError,
378-
arg_name: &'a str,
377+
pub fn arg_from_str<'a, T>(arg: &str, err: &mut InvalidOptionsError,
378+
arg_name: &'a str,
379379
arg_type: &'a str) -> T
380380
where T: FromStr + Default,
381381
<T as FromStr>::Err: fmt::Display {
@@ -409,7 +409,7 @@ impl TokenStorage for JsonTokenStorage {
409409
match token {
410410
None => {
411411
match fs::remove_file(self.path(scope_hash)) {
412-
Err(err) =>
412+
Err(err) =>
413413
match err.kind() {
414414
io::ErrorKind::NotFound => Ok(()),
415415
_ => Err(json::Error::IoError(err))
@@ -422,7 +422,7 @@ impl TokenStorage for JsonTokenStorage {
422422
Ok(mut f) => {
423423
match json::to_writer_pretty(&mut f, &token) {
424424
Ok(_) => Ok(()),
425-
Err(io_err) => Err(json::Error::IoError(io_err)),
425+
Err(serde_err) => Err(serde_err),
426426
}
427427
},
428428
Err(io_err) => Err(json::Error::IoError(io_err))
@@ -453,17 +453,17 @@ impl TokenStorage for JsonTokenStorage {
453453
#[derive(Debug)]
454454
pub enum ApplicationSecretError {
455455
DecoderError((String, json::Error)),
456-
FormatError(String),
456+
FormatError(String),
457457
}
458458

459459
impl fmt::Display for ApplicationSecretError {
460460
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
461461
match *self {
462462
ApplicationSecretError::DecoderError((ref path, ref err))
463-
=> writeln!(f, "Could not decode file at '{}' with error: {}.",
463+
=> writeln!(f, "Could not decode file at '{}' with error: {}.",
464464
path, err),
465465
ApplicationSecretError::FormatError(ref path)
466-
=> writeln!(f, "'installed' field is unset in secret file at '{}'.",
466+
=> writeln!(f, "'installed' field is unset in secret file at '{}'.",
467467
path),
468468
}
469469
}
@@ -483,7 +483,7 @@ impl fmt::Display for ConfigurationError {
483483
match *self {
484484
ConfigurationError::DirectoryCreationFailed((ref dir, ref err))
485485
=> writeln!(f, "Directory '{}' could not be created with error: {}.", dir, err),
486-
ConfigurationError::DirectoryUnset
486+
ConfigurationError::DirectoryUnset
487487
=> writeln!(f, "--config-dir was unset or empty."),
488488
ConfigurationError::HomeExpansionFailed(ref dir)
489489
=> writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'.", dir),
@@ -530,10 +530,10 @@ impl fmt::Display for FieldError {
530530
FieldError::TrailingFieldSep(ref field)
531531
=> writeln!(f, "'{}': Single field separator may not be last character.", field),
532532
FieldError::Unknown(ref field, ref suggestion, ref value) => {
533-
let suffix =
533+
let suffix =
534534
match *suggestion {
535535
Some(ref s) => {
536-
let kv =
536+
let kv =
537537
match *value {
538538
Some(ref v) => format!("{}={}", s, v),
539539
None => s.clone(),
@@ -544,7 +544,7 @@ impl fmt::Display for FieldError {
544544
};
545545
writeln!(f, "Field '{}' does not exist.{}", field, suffix)
546546
},
547-
FieldError::Duplicate(ref cursor)
547+
FieldError::Duplicate(ref cursor)
548548
=> writeln!(f, "Value at '{}' was already set", cursor),
549549
FieldError::Empty
550550
=> writeln!(f, "Field names must not be empty."),
@@ -572,13 +572,13 @@ impl fmt::Display for CLIError {
572572
CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err),
573573
CLIError::Input(ref err) => write!(f, "Input -> {}", err),
574574
CLIError::Field(ref err) => write!(f, "Field -> {}", err),
575-
CLIError::InvalidUploadProtocol(ref proto_name, ref valid_names)
576-
=> writeln!(f, "'{}' is not a valid upload protocol. Choose from one of {}.", proto_name, valid_names.connect(", ")),
577-
CLIError::ParseError(ref arg_name, ref type_name, ref value, ref err_desc)
575+
CLIError::InvalidUploadProtocol(ref proto_name, ref valid_names)
576+
=> writeln!(f, "'{}' is not a valid upload protocol. Choose from one of {}.", proto_name, valid_names.join(", ")),
577+
CLIError::ParseError(ref arg_name, ref type_name, ref value, ref err_desc)
578578
=> writeln!(f, "Failed to parse argument '{}' with value '{}' as {} with error: {}.",
579579
arg_name, value, type_name, err_desc),
580580
CLIError::UnknownParameter(ref param_name, ref possible_values) => {
581-
let mut suffix =
581+
let mut suffix =
582582
match did_you_mean(param_name, &possible_values) {
583583
Some(v) => format!(" Did you mean '{}' ?", v),
584584
None => String::new(),
@@ -632,7 +632,7 @@ pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> {
632632
return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset))
633633
}
634634

635-
let expanded_config_dir =
635+
let expanded_config_dir =
636636
if trdir.as_bytes()[0] == b'~' {
637637
match env::var("HOME").ok().or(env::var("UserProfile").ok()) {
638638
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> {
655655
Ok(expanded_config_dir)
656656
}
657657

658-
pub fn application_secret_from_directory(dir: &str,
659-
secret_basename: &str,
658+
pub fn application_secret_from_directory(dir: &str,
659+
secret_basename: &str,
660660
json_console_secret: &str)
661661
-> Result<ApplicationSecret, CLIError> {
662662
let secret_path = Path::new(dir).join(secret_basename);
@@ -677,10 +677,13 @@ pub fn application_secret_from_directory(dir: &str,
677677
Err(cfe) => cfe,
678678
Ok(mut f) => {
679679
// Assure we convert 'ugly' json string into pretty one
680-
let console_secret: ConsoleApplicationSecret
680+
let console_secret: ConsoleApplicationSecret
681681
= json::from_str(json_console_secret).unwrap();
682682
match json::to_writer_pretty(&mut f, &console_secret) {
683-
Err(io_err) => io_err,
683+
Err(serde_err) => match serde_err {
684+
json::Error::IoError(err) => err,
685+
_ => panic!("Unexpected serde error: {:#?}", serde_err)
686+
},
684687
Ok(_) => continue,
685688
}
686689
}
@@ -691,15 +694,15 @@ pub fn application_secret_from_directory(dir: &str,
691694
},
692695
Ok(mut f) => {
693696
match json::de::from_reader::<_, ConsoleApplicationSecret>(f) {
694-
Err(json::Error::IoError(err)) =>
697+
Err(json::Error::IoError(err)) =>
695698
return secret_io_error(err),
696-
Err(json_err) =>
699+
Err(json_err) =>
697700
return Err(CLIError::Configuration(
698701
ConfigurationError::Secret(
699702
ApplicationSecretError::DecoderError(
700703
(secret_str(), json_err)
701704
)))),
702-
Ok(console_secret) =>
705+
Ok(console_secret) =>
703706
match console_secret.installed {
704707
Some(secret) => return Ok(secret),
705708
None => return Err(
@@ -713,4 +716,4 @@ pub fn application_secret_from_directory(dir: &str,
713716
}
714717
}
715718
unreachable!();
716-
}
719+
}

0 commit comments

Comments
 (0)