Skip to content

Commit 7fd4c30

Browse files
authored
pipeline_context removal (#522)
1 parent f254d90 commit 7fd4c30

22 files changed

+178
-320
lines changed

sdk/core/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ mod models;
2222
mod options;
2323
pub mod parsing;
2424
pub mod pipeline;
25-
mod pipeline_context;
2625
mod policies;
2726
pub mod prelude;
2827
mod request;
@@ -48,7 +47,6 @@ pub use http_client::{new_http_client, to_json, HttpClient};
4847
pub use mock_transaction::constants::*;
4948
pub use models::*;
5049
pub use options::*;
51-
pub use pipeline_context::PipelineContext;
5250
pub use policies::{Policy, PolicyResult};
5351
pub use request::*;
5452
pub use response::*;

sdk/core/src/options.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,18 @@ use std::time::Duration;
1111
///
1212
/// ```
1313
/// use azure_core::{ClientOptions, RetryOptions, TelemetryOptions};
14-
/// let options: ClientOptions<()> = ClientOptions::default()
14+
/// let options: ClientOptions = ClientOptions::default()
1515
/// .retry(RetryOptions::default().max_retries(10u32))
1616
/// .telemetry(TelemetryOptions::default().application_id("my-application"));
1717
/// ```
1818
#[derive(Clone, Debug)]
19-
pub struct ClientOptions<C>
20-
where
21-
C: Send + Sync,
22-
{
19+
pub struct ClientOptions {
2320
// TODO: Expose transport override.
2421
/// Policies called per call.
25-
pub(crate) per_call_policies: Vec<Arc<dyn Policy<C>>>,
22+
pub(crate) per_call_policies: Vec<Arc<dyn Policy>>,
2623

2724
/// Policies called per retry.
28-
pub(crate) per_retry_policies: Vec<Arc<dyn Policy<C>>>,
25+
pub(crate) per_retry_policies: Vec<Arc<dyn Policy>>,
2926

3027
/// Retry options.
3128
pub(crate) retry: RetryOptions,
@@ -37,10 +34,7 @@ where
3734
pub(crate) transport: TransportOptions,
3835
}
3936

40-
impl<C> Default for ClientOptions<C>
41-
where
42-
C: Send + Sync,
43-
{
37+
impl Default for ClientOptions {
4438
fn default() -> Self {
4539
Self {
4640
per_call_policies: Vec::new(),
@@ -52,10 +46,7 @@ where
5246
}
5347
}
5448

55-
impl<C> ClientOptions<C>
56-
where
57-
C: Send + Sync,
58-
{
49+
impl ClientOptions {
5950
pub fn new() -> Self {
6051
Self::default()
6152
}
@@ -72,18 +63,18 @@ where
7263
}
7364

7465
/// A mutable reference to per-call policies.
75-
pub fn per_call_policies_mut(&mut self) -> &mut Vec<Arc<dyn Policy<C>>> {
66+
pub fn per_call_policies_mut(&mut self) -> &mut Vec<Arc<dyn Policy>> {
7667
&mut self.per_call_policies
7768
}
7869

7970
/// A mutable reference to per-retry policies.
80-
pub fn per_retry_policies_mut(&mut self) -> &mut Vec<Arc<dyn Policy<C>>> {
71+
pub fn per_retry_policies_mut(&mut self) -> &mut Vec<Arc<dyn Policy>> {
8172
&mut self.per_retry_policies
8273
}
8374

8475
setters! {
85-
per_call_policies: Vec<Arc<dyn Policy<C>>> => per_call_policies,
86-
per_retry_policies: Vec<Arc<dyn Policy<C>>> => per_retry_policies,
76+
per_call_policies: Vec<Arc<dyn Policy>> => per_call_policies,
77+
per_retry_policies: Vec<Arc<dyn Policy>> => per_retry_policies,
8778
retry: RetryOptions => retry,
8879
telemetry: TelemetryOptions => telemetry,
8980
transport: TransportOptions => transport,
@@ -157,7 +148,7 @@ impl Default for RetryOptions {
157148
}
158149

159150
impl RetryOptions {
160-
pub(crate) fn to_policy<C: Send + Sync>(&self) -> Arc<dyn Policy<C>> {
151+
pub(crate) fn to_policy(&self) -> Arc<dyn Policy> {
161152
match self.mode {
162153
RetryMode::Exponential => Arc::new(ExponentialRetryPolicy::new(
163154
self.delay,

sdk/core/src/pipeline.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(not(target_arch = "wasm32"))]
22
use crate::policies::TransportPolicy;
33
use crate::policies::{CustomHeadersInjectorPolicy, Policy, TelemetryPolicy};
4-
use crate::{ClientOptions, Error, HttpClient, PipelineContext, Request, Response};
4+
use crate::{ClientOptions, Context, Error, HttpClient, Request, Response};
55
use std::sync::Arc;
66

77
/// Execution pipeline.
@@ -32,18 +32,12 @@ use std::sync::Arc;
3232
/// context. For example, in CosmosDB, the generic carries the operation-specific information used by
3333
/// the authorization policy.
3434
#[derive(Debug, Clone)]
35-
pub struct Pipeline<C>
36-
where
37-
C: Send + Sync,
38-
{
35+
pub struct Pipeline {
3936
http_client: Arc<dyn HttpClient>,
40-
pipeline: Vec<Arc<dyn Policy<C>>>,
37+
pipeline: Vec<Arc<dyn Policy>>,
4138
}
4239

43-
impl<C> Pipeline<C>
44-
where
45-
C: Send + Sync,
46-
{
40+
impl Pipeline {
4741
/// Creates a new pipeline given the client library crate name and version,
4842
/// alone with user-specified and client library-specified policies.
4943
///
@@ -52,11 +46,11 @@ where
5246
pub fn new(
5347
crate_name: Option<&'static str>,
5448
crate_version: Option<&'static str>,
55-
options: ClientOptions<C>,
56-
per_call_policies: Vec<Arc<dyn Policy<C>>>,
57-
per_retry_policies: Vec<Arc<dyn Policy<C>>>,
49+
options: ClientOptions,
50+
per_call_policies: Vec<Arc<dyn Policy>>,
51+
per_retry_policies: Vec<Arc<dyn Policy>>,
5852
) -> Self {
59-
let mut pipeline: Vec<Arc<dyn Policy<C>>> = Vec::with_capacity(
53+
let mut pipeline: Vec<Arc<dyn Policy>> = Vec::with_capacity(
6054
options.per_call_policies.len()
6155
+ per_call_policies.len()
6256
+ options.per_retry_policies.len()
@@ -83,7 +77,7 @@ where
8377
#[cfg(not(target_arch = "wasm32"))]
8478
{
8579
#[allow(unused_mut)]
86-
let mut policy: Arc<dyn Policy<_>> =
80+
let mut policy: Arc<dyn Policy> =
8781
Arc::new(TransportPolicy::new(options.transport.clone()));
8882

8983
// This code replaces the default transport policy at runtime if these two conditions
@@ -132,23 +126,15 @@ where
132126
self.http_client.as_ref()
133127
}
134128

135-
pub fn replace_policy(
136-
&mut self,
137-
policy: Arc<dyn Policy<C>>,
138-
position: usize,
139-
) -> Arc<dyn Policy<C>> {
129+
pub fn replace_policy(&mut self, policy: Arc<dyn Policy>, position: usize) -> Arc<dyn Policy> {
140130
std::mem::replace(&mut self.pipeline[position], policy)
141131
}
142132

143-
pub fn policies(&self) -> &[Arc<dyn Policy<C>>] {
133+
pub fn policies(&self) -> &[Arc<dyn Policy>] {
144134
&self.pipeline
145135
}
146136

147-
pub async fn send(
148-
&self,
149-
ctx: &mut PipelineContext<C>,
150-
request: &mut Request,
151-
) -> Result<Response, Error> {
137+
pub async fn send(&self, ctx: &mut Context, request: &mut Request) -> Result<Response, Error> {
152138
self.pipeline[0]
153139
.send(ctx, request, &self.pipeline[1..])
154140
.await

sdk/core/src/pipeline_context.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

sdk/core/src/policies/custom_headers_injector_policy.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::policies::{Policy, PolicyResult};
2-
use crate::{PipelineContext, Request, Response};
2+
use crate::{Context, Request, Response};
33
use http::header::HeaderMap;
44
use std::sync::Arc;
55

@@ -16,18 +16,14 @@ impl From<HeaderMap> for CustomHeaders {
1616
pub struct CustomHeadersInjectorPolicy {}
1717

1818
#[async_trait::async_trait]
19-
impl<C> Policy<C> for CustomHeadersInjectorPolicy
20-
where
21-
C: Send + Sync,
22-
{
19+
impl Policy for CustomHeadersInjectorPolicy {
2320
async fn send(
2421
&self,
25-
ctx: &mut PipelineContext<C>,
22+
ctx: &mut Context,
2623
request: &mut Request,
27-
next: &[Arc<dyn Policy<C>>],
24+
next: &[Arc<dyn Policy>],
2825
) -> PolicyResult<Response> {
29-
if let Some(CustomHeaders(custom_headers)) = ctx.get_inner_context().get::<CustomHeaders>()
30-
{
26+
if let Some(CustomHeaders(custom_headers)) = ctx.get::<CustomHeaders>() {
3127
custom_headers
3228
.iter()
3329
.for_each(|(header_name, header_value)| {

sdk/core/src/policies/mock_transport_player_policy.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::bytes_response::BytesResponse;
2-
use crate::policies::{Policy, PolicyResult};
3-
use crate::{MockFrameworkError, TransportOptions};
4-
use crate::{PipelineContext, Request, Response};
5-
62
use crate::mock_transaction::MockTransaction;
3+
use crate::policies::{Policy, PolicyResult};
4+
use crate::{Context, MockFrameworkError, Request, Response, TransportOptions};
75
use std::sync::Arc;
86

97
#[derive(Debug, Clone)]
@@ -23,15 +21,12 @@ impl MockTransportPlayerPolicy {
2321
}
2422

2523
#[async_trait::async_trait]
26-
impl<C> Policy<C> for MockTransportPlayerPolicy
27-
where
28-
C: Send + Sync,
29-
{
24+
impl Policy for MockTransportPlayerPolicy {
3025
async fn send(
3126
&self,
32-
_ctx: &mut PipelineContext<C>,
27+
_ctx: &mut Context,
3328
request: &mut Request,
34-
next: &[Arc<dyn Policy<C>>],
29+
next: &[Arc<dyn Policy>],
3530
) -> PolicyResult<Response> {
3631
// there must be no more policies
3732
assert_eq!(0, next.len());

sdk/core/src/policies/mock_transport_recorder_policy.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::bytes_response::BytesResponse;
22
use crate::mock_transaction::MockTransaction;
33
use crate::policies::{Policy, PolicyResult};
4-
use crate::{MockFrameworkError, TransportOptions};
5-
use crate::{PipelineContext, Request, Response};
6-
4+
use crate::{Context, MockFrameworkError, Request, Response, TransportOptions};
75
use std::io::Write;
86
use std::sync::Arc;
97

@@ -24,15 +22,12 @@ impl MockTransportRecorderPolicy {
2422
}
2523

2624
#[async_trait::async_trait]
27-
impl<C> Policy<C> for MockTransportRecorderPolicy
28-
where
29-
C: Send + Sync,
30-
{
25+
impl Policy for MockTransportRecorderPolicy {
3126
async fn send(
3227
&self,
33-
_ctx: &mut PipelineContext<C>,
28+
_ctx: &mut Context,
3429
request: &mut Request,
35-
next: &[Arc<dyn Policy<C>>],
30+
next: &[Arc<dyn Policy>],
3631
) -> PolicyResult<Response> {
3732
// there must be no more policies
3833
assert_eq!(0, next.len());

sdk/core/src/policies/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod retry_policies;
77
mod telemetry_policy;
88
mod transport;
99

10-
use crate::{PipelineContext, Request, Response};
10+
use crate::{Context, Request, Response};
1111
pub use custom_headers_injector_policy::{CustomHeaders, CustomHeadersInjectorPolicy};
1212
#[cfg(feature = "mock_transport_framework")]
1313
pub use mock_transport_player_policy::MockTransportPlayerPolicy;
@@ -29,14 +29,11 @@ pub type PolicyResult<T> = Result<T, Box<dyn Error + Send + Sync>>;
2929
/// the implementer to call the following policy.
3030
/// The `C` generic represents the *contents* of the AuthorizationPolicy specific of this pipeline.
3131
#[async_trait::async_trait]
32-
pub trait Policy<C>: Send + Sync + std::fmt::Debug
33-
where
34-
C: Send + Sync,
35-
{
32+
pub trait Policy: Send + Sync + std::fmt::Debug {
3633
async fn send(
3734
&self,
38-
ctx: &mut PipelineContext<C>,
35+
ctx: &mut Context,
3936
request: &mut Request,
40-
next: &[Arc<dyn Policy<C>>],
37+
next: &[Arc<dyn Policy>],
4138
) -> PolicyResult<Response>;
4239
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::policies::{Policy, PolicyResult, Request, Response};
2-
use crate::PipelineContext;
2+
use crate::Context;
33
use std::sync::Arc;
44

55
/// Retry policy that does not retry.
@@ -11,15 +11,12 @@ pub struct NoRetryPolicy {
1111
}
1212

1313
#[async_trait::async_trait]
14-
impl<C> Policy<C> for NoRetryPolicy
15-
where
16-
C: Send + Sync,
17-
{
14+
impl Policy for NoRetryPolicy {
1815
async fn send(
1916
&self,
20-
ctx: &mut PipelineContext<C>,
17+
ctx: &mut Context,
2118
request: &mut Request,
22-
next: &[Arc<dyn Policy<C>>],
19+
next: &[Arc<dyn Policy>],
2320
) -> PolicyResult<Response> {
2421
// just call the following policies and bubble up the error
2522
next[0].send(ctx, request, &next[1..]).await

0 commit comments

Comments
 (0)