Skip to content

Commit

Permalink
Fix build for new Rust stable 1.42.0 (#2688)
Browse files Browse the repository at this point in the history
- `&Option<String>` -> `Option<&str>` conversion using new `Option::as_deref`
  instead of `.as_ref().map(String::as_str)`

- Replace deprecated `std::error::Error::description` with `Display::to_string`

- Replace `Iterator::nth(0)` with `Iterator::next()`

- One of the tests fired a clippy lint about throwing away the error in
  an `Err(_err)` match arm. Make the test use the error.
  • Loading branch information
arsing authored Mar 12, 2020
1 parent afc8969 commit cf01536
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ mod tests {

Ok::<_, Error>(())
}
Err(_err) => panic!("Did not expect a failure."),
Err(err) => panic!("Did not expect a failure: {}", err),
}
.is_ok()
};
Expand Down
4 changes: 2 additions & 2 deletions edgelet/edgelet-kube/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ impl Settings {
}

pub fn iot_hub_hostname(&self) -> Option<&str> {
self.iot_hub_hostname.as_ref().map(String::as_str)
self.iot_hub_hostname.as_deref()
}

pub fn proxy(&self) -> &ProxySettings {
&self.proxy
}

pub fn device_id(&self) -> Option<&str> {
self.device_id.as_ref().map(String::as_str)
self.device_id.as_deref()
}

pub fn device_hub_selector(&self) -> &str {
Expand Down
11 changes: 5 additions & 6 deletions edgelet/iotedge/src/support_bundle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

use std::env;
use std::error::Error as StdError;
use std::ffi::OsString;
use std::fs::File;
use std::io::{stdout, Cursor, Seek};
Expand Down Expand Up @@ -296,7 +295,7 @@ where
("iotedged_err.txt", result.stderr)
}
} else {
let err_message = inspect.err().unwrap().description().to_owned();
let err_message = inspect.err().unwrap().to_string();
println!("Could not find system logs for iotedge. Including error in bundle.\nError message: {}", err_message);
("iotedged_err.txt", err_message.as_bytes().to_vec())
};
Expand Down Expand Up @@ -354,7 +353,7 @@ where
("docker_err.txt", result.stderr)
}
} else {
let err_message = inspect.err().unwrap().description().to_owned();
let err_message = inspect.err().unwrap().to_string();
println!("Could not find system logs for docker. Including error in bundle.\nError message: {}", err_message);
("docker_err.txt", err_message.as_bytes().to_vec())
};
Expand All @@ -377,7 +376,7 @@ where
where
W: Write + Seek + Send,
{
let iotedge = env::args().nth(0).unwrap();
let iotedge = env::args().next().unwrap();
state.print_verbose("Calling iotedge check");

let mut check = ShellCommand::new(iotedge);
Expand Down Expand Up @@ -433,7 +432,7 @@ where
(format!("inspect/{}_err.json", module_name), result.stderr)
}
} else {
let err_message = inspect.err().unwrap().description().to_owned();
let err_message = inspect.err().unwrap().to_string();
println!(
"Could not reach docker. Including error in bundle.\nError message: {}",
err_message
Expand Down Expand Up @@ -523,7 +522,7 @@ where
(format!("network/{}_err.json", network_name), result.stderr)
}
} else {
let err_message = inspect.err().unwrap().description().to_owned();
let err_message = inspect.err().unwrap().to_string();
println!(
"Could not reach docker. Including error in bundle.\nError message: {}",
err_message
Expand Down
30 changes: 15 additions & 15 deletions edgelet/kube-client/src/kube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Config {

impl Config {
pub fn kind(&self) -> Option<&str> {
self.kind.as_ref().map(String::as_str)
self.kind.as_deref()
}

pub fn with_kind(mut self, kind: Option<String>) -> Self {
Expand All @@ -53,7 +53,7 @@ impl Config {
}

pub fn api_version(&self) -> Option<&str> {
self.api_version.as_ref().map(String::as_str)
self.api_version.as_deref()
}

pub fn with_api_version(mut self, api_version: String) -> Self {
Expand Down Expand Up @@ -162,7 +162,7 @@ impl Cluster {
}

pub fn certificate_authority(&self) -> Option<&str> {
self.certificate_authority.as_ref().map(String::as_str)
self.certificate_authority.as_deref()
}

pub fn with_certificate_authority(mut self, certificate_authority: String) -> Self {
Expand All @@ -171,7 +171,7 @@ impl Cluster {
}

pub fn certificate_authority_data(&self) -> Option<&str> {
self.certificate_authority_data.as_ref().map(String::as_str)
self.certificate_authority_data.as_deref()
}

pub fn with_certificate_authority_data(mut self, certificate_authority_data: String) -> Self {
Expand Down Expand Up @@ -234,7 +234,7 @@ pub struct AuthInfo {

impl AuthInfo {
pub fn client_certificate(&self) -> Option<&str> {
self.client_certificate.as_ref().map(String::as_str)
self.client_certificate.as_deref()
}

pub fn with_client_certificate(mut self, client_certificate: String) -> Self {
Expand All @@ -243,7 +243,7 @@ impl AuthInfo {
}

pub fn client_key(&self) -> Option<&str> {
self.client_key.as_ref().map(String::as_str)
self.client_key.as_deref()
}

pub fn with_client_key(mut self, client_key: String) -> Self {
Expand All @@ -252,7 +252,7 @@ impl AuthInfo {
}

pub fn token(&self) -> Option<&str> {
self.token.as_ref().map(String::as_str)
self.token.as_deref()
}

pub fn with_token(mut self, token: String) -> Self {
Expand All @@ -261,7 +261,7 @@ impl AuthInfo {
}

pub fn token_file(&self) -> Option<&str> {
self.token_file.as_ref().map(String::as_str)
self.token_file.as_deref()
}

pub fn with_token_file(mut self, token_file: String) -> Self {
Expand All @@ -270,7 +270,7 @@ impl AuthInfo {
}

pub fn impersonate(&self) -> Option<&str> {
self.impersonate.as_ref().map(String::as_str)
self.impersonate.as_deref()
}

pub fn with_impersonate(mut self, impersonate: String) -> Self {
Expand All @@ -279,7 +279,7 @@ impl AuthInfo {
}

pub fn username(&self) -> Option<&str> {
self.username.as_ref().map(String::as_str)
self.username.as_deref()
}

pub fn with_username(mut self, username: String) -> Self {
Expand All @@ -288,7 +288,7 @@ impl AuthInfo {
}

pub fn password(&self) -> Option<&str> {
self.password.as_ref().map(String::as_str)
self.password.as_deref()
}

pub fn with_password(mut self, password: String) -> Self {
Expand All @@ -297,7 +297,7 @@ impl AuthInfo {
}

pub fn client_certificate_data(&self) -> Option<&str> {
self.client_certificate_data.as_ref().map(String::as_str)
self.client_certificate_data.as_deref()
}

pub fn with_client_certificate_data(mut self, client_certificate_data: String) -> Self {
Expand All @@ -306,7 +306,7 @@ impl AuthInfo {
}

pub fn client_key_data(&self) -> Option<&str> {
self.client_key_data.as_ref().map(String::as_str)
self.client_key_data.as_deref()
}

pub fn with_client_key_data(mut self, client_key_data: String) -> Self {
Expand Down Expand Up @@ -398,7 +398,7 @@ impl ExecConfig {
}

pub fn api_version(&self) -> Option<&str> {
self.api_version.as_ref().map(String::as_str)
self.api_version.as_deref()
}

pub fn with_api_version(mut self, api_version: String) -> Self {
Expand Down Expand Up @@ -497,7 +497,7 @@ impl Context {
}

pub fn namespace(&self) -> Option<&str> {
self.namespace.as_ref().map(String::as_str)
self.namespace.as_deref()
}

pub fn with_namespace(mut self, namespace: String) -> Self {
Expand Down

0 comments on commit cf01536

Please sign in to comment.