Skip to content

Commit 2fe6e64

Browse files
committed
Resolve PR feedback
1 parent e54f626 commit 2fe6e64

File tree

7 files changed

+37
-23
lines changed

7 files changed

+37
-23
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
target
1+
target/
22
Cargo.lock
33
*.rs.bk
44
.vscode/
@@ -9,6 +9,7 @@ sample/
99
\#*\#
1010
\.#*
1111
*~
12+
*.code-workspace
1213
*.swp
1314
*.swo
1415
*.vim

sdk/core/src/macros.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#[macro_export]
2727
macro_rules! setters {
2828
(@single $name:ident : $typ:ty => $transform:expr) => {
29-
// TODO: Declare with_$name when https://github.com/rust-lang/rust/issues/29599 is fixed.
29+
// TODO: Declare using idiomatic with_$name when https://github.com/Azure/azure-sdk-for-rust/issues/292 is resolved.
3030
pub fn $name<T: ::std::convert::Into<$typ>>(self, $name: T) -> Self {
3131
let $name: $typ = $name.into();
3232
Self {
@@ -186,10 +186,7 @@ mod test {
186186

187187
impl Default for Options {
188188
fn default() -> Self {
189-
Options {
190-
a: None,
191-
b: 1,
192-
}
189+
Options { a: None, b: 1 }
193190
}
194191
}
195192

@@ -213,8 +210,7 @@ mod test {
213210

214211
#[test]
215212
fn test_setters() {
216-
let options = Options::default()
217-
.a("test".to_owned());
213+
let options = Options::default().a("test".to_owned());
218214

219215
assert_eq!(Some("test".to_owned()), options.a);
220216
assert_eq!(1, options.b);

sdk/core/src/options.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ use std::sync::Arc;
44
use std::time::Duration;
55

66
/// Client options allow customization of policies, retry options, and more.
7+
///
8+
/// # Examples
9+
///
10+
/// You can override default options and even add your own per-call or per-retry policies:
11+
///
12+
/// ```
13+
/// use azure_core::{ClientOptions, RetryOptions, TelemetryOptions};
14+
/// let options = ClientOptions::default()
15+
/// .retry(RetryOptions::default().max_retries(10u32))
16+
/// .telemetry(TelemetryOptions::default().application_id("my-application"));
17+
/// ```
718
#[derive(Clone, Debug, Default)]
819
pub struct ClientOptions {
920
// TODO: Expose transport override.
@@ -24,6 +35,16 @@ pub struct ClientOptions {
2435
}
2536

2637
impl ClientOptions {
38+
/// A mutable reference to per-call policies.
39+
pub fn mut_per_call_policies(&mut self) -> &mut Vec<Arc<dyn Policy>> {
40+
&mut self.per_call_policies
41+
}
42+
43+
/// A mutable reference to per-retry policies.
44+
pub fn mut_per_retry_policies(&mut self) -> &mut Vec<Arc<dyn Policy>> {
45+
&mut self.per_retry_policies
46+
}
47+
2748
setters! {
2849
per_call_policies: Vec<Arc<dyn Policy>> => per_call_policies,
2950
per_retry_policies: Vec<Arc<dyn Policy>> => per_retry_policies,
@@ -144,7 +165,7 @@ impl TransportOptions {
144165
}
145166

146167
impl Default for TransportOptions {
147-
/// Creates an instance of the ```TransportOptions``` using the enabled HTTP client.
168+
/// Creates an instance of the `TransportOptions` using the enabled HTTP client.
148169
fn default() -> Self {
149170
TransportOptions {
150171
http_client: new_http_client(),

sdk/core/src/pipeline.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ impl Pipeline {
5050
pipeline.extend_from_slice(&per_call_policies);
5151
pipeline.extend_from_slice(&options.per_call_policies);
5252

53-
pipeline.push(Arc::new(TelemetryPolicy::new(
54-
crate_name,
55-
crate_version,
56-
&options.telemetry,
57-
)));
53+
let telemetry_policy = TelemetryPolicy::new(crate_name, crate_version, &options.telemetry);
54+
pipeline.push(Arc::new(telemetry_policy));
5855

5956
let retry_policy = options.retry.to_policy();
6057
pipeline.push(retry_policy);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ pub struct ExponentialRetryPolicy {
2121
impl ExponentialRetryPolicy {
2222
pub(crate) fn new(delay: Duration, max_retries: u32, max_delay: Duration) -> Self {
2323
ExponentialRetryPolicy {
24-
delay: delay,
25-
max_retries: max_retries,
26-
max_delay: max_delay,
24+
delay,
25+
max_retries,
26+
max_delay,
2727
}
2828
}
2929

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ pub struct FixedRetryPolicy {
2020
impl FixedRetryPolicy {
2121
pub(crate) fn new(delay: Duration, max_retries: u32, max_delay: Duration) -> Self {
2222
FixedRetryPolicy {
23-
delay: delay,
24-
max_retries: max_retries,
25-
max_delay: max_delay,
23+
delay,
24+
max_retries,
25+
max_delay,
2626
}
2727
}
2828

sdk/cosmos/src/clients/cosmos_client.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use crate::resources::permission::AuthorizationToken;
55
use crate::resources::ResourceType;
66
use crate::{requests, ReadonlyString};
77

8-
use azure_core::*;
98
use azure_core::pipeline::Pipeline;
109
use azure_core::Context;
1110
use azure_core::HttpClient;
1211
use azure_core::Request;
12+
use azure_core::*;
1313
use http::request::Builder as RequestBuilder;
1414
use http::{header, HeaderValue};
1515
use ring::hmac;
@@ -42,8 +42,7 @@ impl CosmosOptions {
4242
pub fn with_client(client: Arc<dyn HttpClient>) -> Self {
4343
Self {
4444
options: ClientOptions::default()
45-
.retry(RetryOptions::default()
46-
.mode(RetryMode::Fixed))
45+
.retry(RetryOptions::default().mode(RetryMode::Fixed))
4746
.transport(TransportOptions::new(client)),
4847
}
4948
}

0 commit comments

Comments
 (0)