Skip to content

Commit

Permalink
address clippy warnings for azure_core (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
demoray committed Sep 19, 2023
1 parent 7be52f6 commit f449cce
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 21 deletions.
8 changes: 3 additions & 5 deletions sdk/core/src/date/rfc1123.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use serde::{self, Deserialize, Deserializer, Serializer};
use crate::date::{parse_rfc1123, to_rfc1123};
use serde::{self, de, Deserialize, Deserializer, Serializer};
use time::OffsetDateTime;

use crate::date::*;
use serde::de;

pub fn deserialize<'de, D>(deserializer: D) -> Result<OffsetDateTime, D::Error>
where
D: Deserializer<'de>,
Expand All @@ -20,7 +18,7 @@ where
}

pub mod option {
use crate::date::*;
use crate::date::{parse_rfc1123, to_rfc1123};
use serde::{Deserialize, Deserializer, Serializer};
use time::OffsetDateTime;

Expand Down
4 changes: 2 additions & 2 deletions sdk/core/src/error/http_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub(crate) fn get_error_code_from_body(body: &[u8]) -> Option<String> {
let nested = || json.get("error")?.get("code")?.as_str();
let top_level = || json.get("code")?.as_str();
let code = nested().or_else(top_level);
code.map(|c| c.to_owned())
code.map(ToOwned::to_owned)
}

/// Gets the error message if it's present in the body
Expand All @@ -122,5 +122,5 @@ pub(crate) fn get_error_message_from_body(body: &[u8]) -> Option<String> {
let nested = || json.get("error")?.get("message")?.as_str();
let top_level = || json.get("message")?.as_str();
let code = nested().or_else(top_level);
code.map(|c| c.to_owned())
code.map(ToOwned::to_owned)
}
7 changes: 4 additions & 3 deletions sdk/core/src/headers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,10 @@ const fn ensure_no_uppercase(s: &str) {
let mut i = 0;
while i < bytes.len() {
let byte = bytes[i];
if byte >= 65u8 && byte <= 90u8 {
panic!("header names must not contain any uppercase letters");
}
assert!(
!(byte >= 65u8 && byte <= 90u8),
"header names must not contain uppercase letters"
);
i += 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/src/http_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod reqwest;
#[cfg(not(any(feature = "enable_reqwest", feature = "enable_reqwest_rustls")))]
use self::noop::NoopClient;
#[cfg(any(feature = "enable_reqwest", feature = "enable_reqwest_rustls"))]
use self::reqwest::*;
use self::reqwest::new_reqwest_client;
use crate::error::ErrorKind;
use async_trait::async_trait;
use bytes::Bytes;
Expand Down
17 changes: 8 additions & 9 deletions sdk/core/src/http_client/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl HttpClient for ::reqwest::Client {
async fn execute_request(&self, request: &crate::Request) -> crate::Result<crate::Response> {
let url = request.url().clone();
let method = request.method();
let mut req = self.request(try_from_method(method)?, url.clone());
let mut req = self.request(try_from_method(*method)?, url.clone());
for (name, value) in request.headers().iter() {
req = req.header(name.as_str(), value.as_str());
}
Expand Down Expand Up @@ -65,22 +65,21 @@ fn to_headers(map: &::reqwest::header::HeaderMap) -> crate::headers::Headers {
.iter()
.filter_map(|(k, v)| {
let key = k.as_str();
match std::str::from_utf8(v.as_bytes()) {
Ok(value) => Some((
if let Ok(value) = v.to_str() {
Some((
crate::headers::HeaderName::from(key.to_owned()),
crate::headers::HeaderValue::from(value.to_owned()),
)),
Err(_) => {
log::warn!("header value for `{key}` is not utf8");
None
}
))
} else {
log::warn!("header value for `{key}` is not utf8");
None
}
})
.collect::<HashMap<_, _>>();
crate::headers::Headers::from(map)
}

fn try_from_method(method: &crate::Method) -> crate::Result<::reqwest::Method> {
fn try_from_method(method: crate::Method) -> crate::Result<::reqwest::Method> {
match method {
crate::Method::Connect => Ok(::reqwest::Method::CONNECT),
crate::Method::Delete => Ok(::reqwest::Method::DELETE),
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/src/lro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub mod location {
Url,
};

#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub enum FinalState {
AzureAsyncOperation,
Location,
Expand Down

0 comments on commit f449cce

Please sign in to comment.