Skip to content

Commit 47fba25

Browse files
authored
remove pipeline from public api (#335)
1 parent 7a82288 commit 47fba25

File tree

10 files changed

+85
-35
lines changed

10 files changed

+85
-35
lines changed

actix-server/examples/tcp-echo.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,25 @@
99
//! Start typing. When you press enter the typed line will be echoed back. The server will log
1010
//! the length of each line it echos and the total size of data sent when the connection is closed.
1111
12-
use std::sync::{
13-
atomic::{AtomicUsize, Ordering},
14-
Arc,
12+
use std::{
13+
env, io,
14+
sync::{
15+
atomic::{AtomicUsize, Ordering},
16+
Arc,
17+
},
1518
};
16-
use std::{env, io};
1719

1820
use actix_rt::net::TcpStream;
1921
use actix_server::Server;
20-
use actix_service::pipeline_factory;
22+
use actix_service::{fn_service, ServiceFactoryExt as _};
2123
use bytes::BytesMut;
2224
use futures_util::future::ok;
2325
use log::{error, info};
2426
use tokio::io::{AsyncReadExt, AsyncWriteExt};
2527

2628
#[actix_rt::main]
2729
async fn main() -> io::Result<()> {
28-
env::set_var("RUST_LOG", "actix=trace,basic=trace");
30+
env::set_var("RUST_LOG", "info");
2931
env_logger::init();
3032

3133
let count = Arc::new(AtomicUsize::new(0));
@@ -41,7 +43,7 @@ async fn main() -> io::Result<()> {
4143
let count = Arc::clone(&count);
4244
let num2 = Arc::clone(&count);
4345

44-
pipeline_factory(move |mut stream: TcpStream| {
46+
fn_service(move |mut stream: TcpStream| {
4547
let count = Arc::clone(&count);
4648

4749
async move {

actix-service/CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changes
22

33
## Unreleased - 2021-xx-xx
4+
* Removed pipeline and related structs/functions. [#335]
5+
6+
[#335]: https://github.com/actix/actix-net/pull/335
47

58

69
## 2.0.0-beta.5 - 2021-03-15

actix-service/src/and_then.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use pin_project_lite::pin_project;
1111

1212
use super::{Service, ServiceFactory};
1313

14-
/// Service for the `and_then` combinator, chaining a computation onto the end
15-
/// of another service which completes successfully.
14+
/// Service for the `and_then` combinator, chaining a computation onto the end of another service
15+
/// which completes successfully.
1616
///
1717
/// This is created by the `Pipeline::and_then` method.
18-
pub(crate) struct AndThenService<A, B, Req>(Rc<(A, B)>, PhantomData<Req>);
18+
pub struct AndThenService<A, B, Req>(Rc<(A, B)>, PhantomData<Req>);
1919

2020
impl<A, B, Req> AndThenService<A, B, Req> {
2121
/// Create new `AndThen` combinator
@@ -64,7 +64,7 @@ where
6464
}
6565

6666
pin_project! {
67-
pub(crate) struct AndThenServiceResponse<A, B, Req>
67+
pub struct AndThenServiceResponse<A, B, Req>
6868
where
6969
A: Service<Req>,
7070
B: Service<A::Response, Error = A::Error>,
@@ -117,7 +117,7 @@ where
117117
}
118118

119119
/// `.and_then()` service factory combinator
120-
pub(crate) struct AndThenServiceFactory<A, B, Req>
120+
pub struct AndThenServiceFactory<A, B, Req>
121121
where
122122
A: ServiceFactory<Req>,
123123
A::Config: Clone,
@@ -200,7 +200,7 @@ where
200200
}
201201

202202
pin_project! {
203-
pub(crate) struct AndThenServiceFactoryResponse<A, B, Req>
203+
pub struct AndThenServiceFactoryResponse<A, B, Req>
204204
where
205205
A: ServiceFactory<Req>,
206206
B: ServiceFactory<A::Response>,
@@ -272,7 +272,9 @@ mod tests {
272272
use futures_util::future::lazy;
273273

274274
use crate::{
275-
fn_factory, ok, pipeline, pipeline_factory, ready, Ready, Service, ServiceFactory,
275+
fn_factory, ok,
276+
pipeline::{pipeline, pipeline_factory},
277+
ready, Ready, Service, ServiceFactory,
276278
};
277279

278280
struct Srv1(Rc<Cell<usize>>);

actix-service/src/apply.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ mod tests {
214214
use futures_util::future::lazy;
215215

216216
use super::*;
217-
use crate::{ok, pipeline, pipeline_factory, Ready, Service, ServiceFactory};
217+
use crate::{
218+
ok,
219+
pipeline::{pipeline, pipeline_factory},
220+
Ready, Service, ServiceFactory,
221+
};
218222

219223
#[derive(Clone)]
220224
struct Srv;

actix-service/src/ext.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
use crate::{
2-
map::Map, map_err::MapErr, transform_err::TransformMapInitErr, Service, ServiceFactory,
3-
Transform,
2+
and_then::{AndThenService, AndThenServiceFactory},
3+
map::Map,
4+
map_err::MapErr,
5+
transform_err::TransformMapInitErr,
6+
IntoService, IntoServiceFactory, Service, ServiceFactory, Transform,
47
};
58

9+
/// An extension trait for [`Service`]s that provides a variety of convenient adapters.
610
pub trait ServiceExt<Req>: Service<Req> {
711
/// Map this service's output to a different type, returning a new service
812
/// of the resulting type.
@@ -36,10 +40,27 @@ pub trait ServiceExt<Req>: Service<Req> {
3640
{
3741
MapErr::new(self, f)
3842
}
43+
44+
/// Call another service after call to this one has resolved successfully.
45+
///
46+
/// This function can be used to chain two services together and ensure that the second service
47+
/// isn't called until call to the fist service have finished. Result of the call to the first
48+
/// service is used as an input parameter for the second service's call.
49+
///
50+
/// Note that this function consumes the receiving service and returns a wrapped version of it.
51+
fn and_then<I, S1>(self, service: I) -> AndThenService<Self, S1, Req>
52+
where
53+
Self: Sized,
54+
I: IntoService<S1, Self::Response>,
55+
S1: Service<Self::Response, Error = Self::Error>,
56+
{
57+
AndThenService::new(self, service.into_service())
58+
}
3959
}
4060

4161
impl<S, Req> ServiceExt<Req> for S where S: Service<Req> {}
4262

63+
/// An extension trait for [`ServiceFactory`]s that provides a variety of convenient adapters.
4364
pub trait ServiceFactoryExt<Req>: ServiceFactory<Req> {
4465
/// Map this service's output to a different type, returning a new service
4566
/// of the resulting type.
@@ -68,10 +89,27 @@ pub trait ServiceFactoryExt<Req>: ServiceFactory<Req> {
6889
{
6990
crate::map_init_err::MapInitErr::new(self, f)
7091
}
92+
93+
/// Call another service after call to this one has resolved successfully.
94+
fn and_then<I, SF1>(self, factory: I) -> AndThenServiceFactory<Self, SF1, Req>
95+
where
96+
Self: Sized,
97+
Self::Config: Clone,
98+
I: IntoServiceFactory<SF1, Self::Response>,
99+
SF1: ServiceFactory<
100+
Self::Response,
101+
Config = Self::Config,
102+
Error = Self::Error,
103+
InitError = Self::InitError,
104+
>,
105+
{
106+
AndThenServiceFactory::new(self, factory.into_factory())
107+
}
71108
}
72109

73110
impl<SF, Req> ServiceFactoryExt<Req> for SF where SF: ServiceFactory<Req> {}
74111

112+
/// An extension trait for [`Transform`]s that provides a variety of convenient adapters.
75113
pub trait TransformExt<S, Req>: Transform<S, Req> {
76114
/// Return a new `Transform` whose init error is mapped to to a different type.
77115
fn map_init_err<F, E>(self, f: F) -> TransformMapInitErr<Self, S, Req, F, E>

actix-service/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ pub use self::apply_cfg::{apply_cfg, apply_cfg_factory};
3838
pub use self::ext::{ServiceExt, ServiceFactoryExt, TransformExt};
3939
pub use self::fn_service::{fn_factory, fn_factory_with_config, fn_service};
4040
pub use self::map_config::{map_config, unit_config};
41-
pub use self::pipeline::{pipeline, pipeline_factory, Pipeline, PipelineFactory};
4241
pub use self::transform::{apply, ApplyTransform, Transform};
4342

4443
#[allow(unused_imports)]

actix-service/src/pipeline.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// TODO: see if pipeline is necessary
2+
#![allow(dead_code)]
3+
14
use core::{
25
marker::PhantomData,
36
task::{Context, Poll},
@@ -11,7 +14,7 @@ use crate::then::{ThenService, ThenServiceFactory};
1114
use crate::{IntoService, IntoServiceFactory, Service, ServiceFactory};
1215

1316
/// Construct new pipeline with one service in pipeline chain.
14-
pub fn pipeline<I, S, Req>(service: I) -> Pipeline<S, Req>
17+
pub(crate) fn pipeline<I, S, Req>(service: I) -> Pipeline<S, Req>
1518
where
1619
I: IntoService<S, Req>,
1720
S: Service<Req>,
@@ -23,7 +26,7 @@ where
2326
}
2427

2528
/// Construct new pipeline factory with one service factory.
26-
pub fn pipeline_factory<I, SF, Req>(factory: I) -> PipelineFactory<SF, Req>
29+
pub(crate) fn pipeline_factory<I, SF, Req>(factory: I) -> PipelineFactory<SF, Req>
2730
where
2831
I: IntoServiceFactory<SF, Req>,
2932
SF: ServiceFactory<Req>,
@@ -35,7 +38,7 @@ where
3538
}
3639

3740
/// Pipeline service - pipeline allows to compose multiple service into one service.
38-
pub struct Pipeline<S, Req> {
41+
pub(crate) struct Pipeline<S, Req> {
3942
service: S,
4043
_phantom: PhantomData<Req>,
4144
}
@@ -157,7 +160,7 @@ impl<S: Service<Req>, Req> Service<Req> for Pipeline<S, Req> {
157160
}
158161

159162
/// Pipeline factory
160-
pub struct PipelineFactory<SF, Req> {
163+
pub(crate) struct PipelineFactory<SF, Req> {
161164
factory: SF,
162165
_phantom: PhantomData<Req>,
163166
}

actix-service/src/then.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,11 @@ mod tests {
246246

247247
use futures_util::future::lazy;
248248

249-
use crate::{err, ok, pipeline, pipeline_factory, ready, Ready, Service, ServiceFactory};
249+
use crate::{
250+
err, ok,
251+
pipeline::{pipeline, pipeline_factory},
252+
ready, Ready, Service, ServiceFactory,
253+
};
250254

251255
#[derive(Clone)]
252256
struct Srv1(Rc<Cell<usize>>);

actix-service/src/transform.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ where
2121
ApplyTransform::new(t, factory.into_factory())
2222
}
2323

24-
/// The `Transform` trait defines the interface of a service factory that wraps inner service
25-
/// during construction.
24+
/// Defines the interface of a service factory that wraps inner service during construction.
2625
///
27-
/// Transform(middleware) wraps inner service and runs during inbound and/or outbound processing in
28-
/// the request/response lifecycle. It may modify request and/or response.
26+
/// Transformers wrap an inner service and runs during inbound and/or outbound processing in the
27+
/// service lifecycle. It may modify request and/or response.
2928
///
3029
/// For example, a timeout service wrapper:
3130
///

actix-tls/examples/tcp-rustls.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,17 @@ use std::{
3131

3232
use actix_rt::net::TcpStream;
3333
use actix_server::Server;
34-
use actix_service::pipeline_factory;
34+
use actix_service::ServiceFactoryExt as _;
3535
use actix_tls::accept::rustls::{Acceptor as RustlsAcceptor, TlsStream};
3636
use futures_util::future::ok;
3737
use log::info;
3838
use rustls::{
3939
internal::pemfile::certs, internal::pemfile::rsa_private_keys, NoClientAuth, ServerConfig,
4040
};
4141

42-
#[derive(Debug)]
43-
struct ServiceState {
44-
num: Arc<AtomicUsize>,
45-
}
46-
4742
#[actix_rt::main]
4843
async fn main() -> io::Result<()> {
49-
env::set_var("RUST_LOG", "actix=trace,basic=trace");
44+
env::set_var("RUST_LOG", "info");
5045
env_logger::init();
5146

5247
let mut tls_config = ServerConfig::new(NoClientAuth::new());
@@ -73,7 +68,8 @@ async fn main() -> io::Result<()> {
7368
let count = Arc::clone(&count);
7469

7570
// Set up TLS service factory
76-
pipeline_factory(tls_acceptor.clone())
71+
tls_acceptor
72+
.clone()
7773
.map_err(|err| println!("Rustls error: {:?}", err))
7874
.and_then(move |stream: TlsStream<TcpStream>| {
7975
let num = count.fetch_add(1, Ordering::Relaxed);

0 commit comments

Comments
 (0)