Skip to content

Commit 3058ce1

Browse files
authored
address upcoming clippy issues (#912)
1 parent 6042f75 commit 3058ce1

22 files changed

+49
-50
lines changed

sdk/core/src/error/http_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ impl HttpError {
2727
error_code = error_code.or_else(|| get_error_code_from_body(&body));
2828
HttpError {
2929
status,
30-
headers,
3130
error_code,
31+
headers,
3232
body,
3333
}
3434
}

sdk/core/src/error/mod.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,19 @@ impl Error {
138138
/// Get the `ErrorKind` of this `Error`
139139
pub fn kind(&self) -> &ErrorKind {
140140
match &self.context {
141-
Context::Simple(kind) => kind,
142-
Context::Message { kind, .. } => kind,
143-
Context::Custom(Custom { kind, .. }) => kind,
144-
Context::Full(Custom { kind, .. }, _) => kind,
141+
Context::Simple(kind)
142+
| Context::Message { kind, .. }
143+
| Context::Custom(Custom { kind, .. })
144+
| Context::Full(Custom { kind, .. }, _) => kind,
145145
}
146146
}
147147

148148
/// Consumes the Error, returning its inner error (if any).
149149
pub fn into_inner(self) -> std::result::Result<Box<dyn std::error::Error + Send + Sync>, Self> {
150150
match self.context {
151-
Context::Custom(Custom { error, .. }) => Ok(error),
152-
Context::Full(Custom { error, .. }, _) => Ok(error),
151+
Context::Custom(Custom { error, .. }) | Context::Full(Custom { error, .. }, _) => {
152+
Ok(error)
153+
}
153154
_ => Err(self),
154155
}
155156
}
@@ -171,8 +172,9 @@ impl Error {
171172
/// Returns a reference to the inner error wrapped by this error (if any).
172173
pub fn get_ref(&self) -> Option<&(dyn std::error::Error + Send + Sync + 'static)> {
173174
match &self.context {
174-
Context::Custom(Custom { error, .. }) => Some(error.as_ref()),
175-
Context::Full(Custom { error, .. }, _) => Some(error.as_ref()),
175+
Context::Custom(Custom { error, .. }) | Context::Full(Custom { error, .. }, _) => {
176+
Some(error.as_ref())
177+
}
176178
_ => None,
177179
}
178180
}
@@ -185,8 +187,9 @@ impl Error {
185187
/// Returns a mutable reference to the inner error wrapped by this error (if any).
186188
pub fn get_mut(&mut self) -> Option<&mut (dyn std::error::Error + Send + Sync + 'static)> {
187189
match &mut self.context {
188-
Context::Custom(Custom { error, .. }) => Some(error.as_mut()),
189-
Context::Full(Custom { error, .. }, _) => Some(error.as_mut()),
190+
Context::Custom(Custom { error, .. }) | Context::Full(Custom { error, .. }, _) => {
191+
Some(error.as_mut())
192+
}
190193
_ => None,
191194
}
192195
}
@@ -200,8 +203,9 @@ impl Error {
200203
impl std::error::Error for Error {
201204
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
202205
match &self.context {
203-
Context::Custom(Custom { error, .. }) => error.source(),
204-
Context::Full(Custom { error, .. }, _) => error.source(),
206+
Context::Custom(Custom { error, .. }) | Context::Full(Custom { error, .. }, _) => {
207+
error.source()
208+
}
205209
_ => None,
206210
}
207211
}

sdk/core/src/http_client/reqwest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl HttpClient for ::reqwest::Client {
3232
.context(ErrorKind::Io, "failed to execute `reqwest` request")?;
3333

3434
let status = rsp.status();
35-
let headers = to_headers(rsp.headers())?;
35+
let headers = to_headers(rsp.headers());
3636
let body: PinnedStream = Box::pin(rsp.bytes_stream().map_err(|error| {
3737
Error::full(
3838
ErrorKind::Io,
@@ -49,7 +49,7 @@ impl HttpClient for ::reqwest::Client {
4949
}
5050
}
5151

52-
fn to_headers(map: &::reqwest::header::HeaderMap) -> crate::Result<crate::headers::Headers> {
52+
fn to_headers(map: &::reqwest::header::HeaderMap) -> crate::headers::Headers {
5353
let map = map
5454
.iter()
5555
.filter_map(|(k, v)| {
@@ -66,7 +66,7 @@ fn to_headers(map: &::reqwest::header::HeaderMap) -> crate::Result<crate::header
6666
}
6767
})
6868
.collect::<HashMap<_, _>>();
69-
Ok(crate::headers::Headers::from(map))
69+
crate::headers::Headers::from(map)
7070
}
7171

7272
fn try_from_method(method: &crate::Method) -> crate::Result<::reqwest::Method> {

sdk/core/src/pageable.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ where
5252

5353
let next_state = response
5454
.continuation()
55-
.map(State::Continuation)
56-
.unwrap_or(State::Done);
55+
.map_or(State::Done, State::Continuation);
5756

5857
Some((Ok(response), next_state))
5958
}

sdk/core/src/pipeline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use std::sync::Arc;
2929
///
3030
/// The `C` generic contains the pipeline-specific context. Different crates can pass
3131
/// different contexts using this generic. This way each crate can have its own specific pipeline
32-
/// context. For example, in CosmosDB, the generic carries the operation-specific information used by
32+
/// context. For example, in `CosmosDB`, the generic carries the operation-specific information used by
3333
/// the authorization policy.
3434
#[derive(Debug, Clone)]
3535
pub struct Pipeline {

sdk/core/src/policies/retry_policies/exponential_retry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl super::RetryPolicy for ExponentialRetryPolicy {
4040

4141
fn sleep_duration(&self, retry_count: u32) -> Duration {
4242
let sleep_ms = self.delay.as_millis() as u64 * u64::pow(2u64, retry_count - 1)
43-
+ rand::random::<u8>() as u64;
43+
+ u64::from(rand::random::<u8>());
4444
Duration::from_millis(sleep_ms)
4545
}
4646
}

sdk/core/src/policies/retry_policies/fixed_retry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl super::RetryPolicy for FixedRetryPolicy {
3838
}
3939

4040
fn sleep_duration(&self, _retry_count: u32) -> Duration {
41-
let sleep_ms = self.delay.as_millis() as u64 + rand::random::<u8>() as u64;
41+
let sleep_ms = self.delay.as_millis() as u64 + u64::from(rand::random::<u8>());
4242
Duration::from_millis(sleep_ms)
4343
}
4444
}

sdk/core/src/policies/retry_policies/retry_policy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ where
6464
let error = Error::full(
6565
ErrorKind::http_response(
6666
status,
67-
http_error.error_code().map(|s| s.to_owned()),
67+
http_error.error_code().map(std::borrow::ToOwned::to_owned),
6868
),
6969
http_error,
7070
"server returned error status which will not be retried",

sdk/core/src/request.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl Request {
6363
let mut result = self.url.path().to_owned();
6464
if let Some(query) = self.url.query() {
6565
result.push('?');
66-
result.push_str(query)
66+
result.push_str(query);
6767
}
6868
result
6969
}
@@ -74,7 +74,7 @@ impl Request {
7474

7575
pub fn insert_headers<T: AsHeaders>(&mut self, headers: &T) {
7676
for (name, value) in headers.as_headers() {
77-
self.insert_header(name, value)
77+
self.insert_header(name, value);
7878
}
7979
}
8080

@@ -95,7 +95,7 @@ impl Request {
9595
K: Into<crate::headers::HeaderName>,
9696
V: Into<crate::headers::HeaderValue>,
9797
{
98-
self.headers.insert(key, value)
98+
self.headers.insert(key, value);
9999
}
100100

101101
pub fn add_optional_header_ref<T: crate::Header>(&mut self, item: &Option<&T>) {
@@ -106,11 +106,11 @@ impl Request {
106106

107107
pub fn add_optional_header<T: crate::Header>(&mut self, item: &Option<T>) {
108108
if let Some(item) = item {
109-
self.insert_header(item.name(), item.value())
109+
self.insert_header(item.name(), item.value());
110110
}
111111
}
112112

113113
pub fn add_mandatory_header<T: crate::Header>(&mut self, item: &T) {
114-
self.insert_header(item.name(), item.value())
114+
self.insert_header(item.name(), item.value());
115115
}
116116
}

sdk/core/src/request_options/accept.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ impl Header for Accept {
3434
}
3535

3636
fn value(&self) -> headers::HeaderValue {
37-
self.0.to_owned().into()
37+
self.0.clone().into()
3838
}
3939
}

sdk/core/src/request_options/accept_encoding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ impl Header for AcceptEncoding {
3535
}
3636

3737
fn value(&self) -> headers::HeaderValue {
38-
self.0.to_owned().into()
38+
self.0.clone().into()
3939
}
4040
}

sdk/core/src/request_options/activity_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ impl Header for ActivityId {
2424
}
2525

2626
fn value(&self) -> headers::HeaderValue {
27-
self.0.to_owned().into()
27+
self.0.clone().into()
2828
}
2929
}

sdk/core/src/request_options/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ impl Header for App {
2525
}
2626

2727
fn value(&self) -> headers::HeaderValue {
28-
self.0.to_owned().into()
28+
self.0.clone().into()
2929
}
3030
}

sdk/core/src/request_options/client_request_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ impl Header for ClientRequestId {
2626
}
2727

2828
fn value(&self) -> headers::HeaderValue {
29-
self.0.to_owned().into()
29+
self.0.clone().into()
3030
}
3131
}

sdk/core/src/request_options/client_version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ impl Header for ClientVersion {
2626
}
2727

2828
fn value(&self) -> headers::HeaderValue {
29-
self.0.to_owned().into()
29+
self.0.clone().into()
3030
}
3131
}

sdk/core/src/request_options/if_match_condition.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ impl Header for IfMatchCondition {
1717

1818
fn value(&self) -> headers::HeaderValue {
1919
match self.clone() {
20-
IfMatchCondition::Match(etag) => etag,
21-
IfMatchCondition::NotMatch(etag) => etag,
20+
IfMatchCondition::Match(etag) | IfMatchCondition::NotMatch(etag) => etag.into(),
2221
}
23-
.into()
2422
}
2523
}

sdk/core/src/request_options/if_modified_since_condition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ impl Header for IfModifiedSinceCondition {
1818

1919
fn value(&self) -> headers::HeaderValue {
2020
match self {
21-
IfModifiedSinceCondition::Modified(date) => date.to_rfc2822(),
22-
IfModifiedSinceCondition::Unmodified(date) => date.to_rfc2822(),
21+
IfModifiedSinceCondition::Modified(date)
22+
| IfModifiedSinceCondition::Unmodified(date) => date.to_rfc2822(),
2323
}
2424
.into()
2525
}

sdk/core/src/request_options/if_source_match_condition.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ impl Header for IfSourceMatchCondition {
1616

1717
fn value(&self) -> headers::HeaderValue {
1818
match self.clone() {
19-
IfSourceMatchCondition::Match(etag) => etag,
20-
IfSourceMatchCondition::NotMatch(etag) => etag,
19+
IfSourceMatchCondition::Match(etag) | IfSourceMatchCondition::NotMatch(etag) => {
20+
etag.into()
21+
}
2122
}
22-
.into()
2323
}
2424
}

sdk/core/src/request_options/if_source_modified_since_condition.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ impl Header for IfSourceModifiedSinceCondition {
1717

1818
fn value(&self) -> headers::HeaderValue {
1919
match self {
20-
IfSourceModifiedSinceCondition::Modified(date) => date.to_rfc2822(),
21-
IfSourceModifiedSinceCondition::Unmodified(date) => date.to_rfc2822(),
20+
IfSourceModifiedSinceCondition::Modified(date)
21+
| IfSourceModifiedSinceCondition::Unmodified(date) => date.to_rfc2822().into(),
2222
}
23-
.into()
2423
}
2524
}

sdk/core/src/request_options/sequence_number_condition.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ impl Header for SequenceNumberCondition {
1818

1919
fn value(&self) -> headers::HeaderValue {
2020
match self {
21-
SequenceNumberCondition::Equal(val) => val.to_string(),
22-
SequenceNumberCondition::LessOrEqual(val) => val.to_string(),
23-
SequenceNumberCondition::Less(val) => val.to_string(),
21+
SequenceNumberCondition::Equal(val)
22+
| SequenceNumberCondition::LessOrEqual(val)
23+
| SequenceNumberCondition::Less(val) => val.to_string().into(),
2424
}
25-
.into()
2625
}
2726
}

sdk/core/src/request_options/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ impl Header for User {
2525
}
2626

2727
fn value(&self) -> headers::HeaderValue {
28-
self.0.to_owned().into()
28+
self.0.clone().into()
2929
}
3030
}

sdk/core/src/request_options/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ impl Header for Version {
2424
}
2525

2626
fn value(&self) -> headers::HeaderValue {
27-
self.0.to_owned().into()
27+
self.0.clone().into()
2828
}
2929
}

0 commit comments

Comments
 (0)