Skip to content

Commit 5f37d85

Browse files
committed
move service to separate crate
1 parent e8aa73a commit 5f37d85

File tree

14 files changed

+183
-74
lines changed

14 files changed

+183
-74
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ matrix:
1616

1717
env:
1818
global:
19-
# - RUSTFLAGS="-C link-dead-code"
19+
- RUSTFLAGS="-C link-dead-code"
2020
- OPENSSL_VERSION=openssl-1.0.2
2121

2222
before_install:
@@ -33,13 +33,15 @@ script:
3333
if [[ "$TRAVIS_RUST_VERSION" != "nightly" ]]; then
3434
cargo clean
3535
cargo test --features="ssl,tls,rust-tls" -- --nocapture
36+
cd actix-service && cargo test
3637
fi
3738
- |
3839
if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then
3940
RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install -f cargo-tarpaulin
4041
cargo tarpaulin --features="ssl,tls,rust-tls" --out Xml
4142
bash <(curl -s https://codecov.io/bash)
4243
echo "Uploaded code coverage"
44+
cd actix-service && cargo tarpaulin --out Xml && bash <(curl -s https://codecov.io/bash)
4345
fi
4446
4547
# Upload docs

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ license = "MIT/Apache-2.0"
1313
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"]
1414
edition = "2018"
1515

16+
[workspace]
17+
members = [
18+
"./",
19+
"actix-service",
20+
]
21+
1622
[package.metadata.docs.rs]
1723
features = ["ssl", "tls", "rust-tls"]
1824

@@ -41,6 +47,8 @@ cell = []
4147

4248
[dependencies]
4349
actix = "0.7.6"
50+
# actix-service = "0.1"
51+
actix-service = { path="./actix-service" }
4452

4553
log = "0.4"
4654
num_cpus = "1.0"

actix-service/Cargo.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "actix-service"
3+
version = "0.1.0"
4+
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
5+
description = "Actix Service"
6+
keywords = ["network", "framework", "async", "futures"]
7+
homepage = "https://actix.rs"
8+
repository = "https://github.com/actix/actix-net.git"
9+
documentation = "https://docs.rs/actix-service/"
10+
categories = ["network-programming", "asynchronous"]
11+
license = "MIT/Apache-2.0"
12+
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"]
13+
edition = "2018"
14+
workspace = "../"
15+
16+
[badges]
17+
travis-ci = { repository = "actix/actix-service", branch = "master" }
18+
# appveyor = { repository = "fafhrd91/actix-web-hdy9d" }
19+
codecov = { repository = "actix/actix-service", branch = "master", service = "github" }
20+
21+
[lib]
22+
name = "actix_service"
23+
path = "src/lib.rs"
24+
25+
[dependencies]
26+
futures = "0.1.24"
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ where
4646

4747
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
4848
try_ready!(self.a.poll_ready());
49-
self.b.borrow_mut().poll_ready()
49+
self.b.get_mut().poll_ready()
5050
}
5151

5252
fn call(&mut self, req: Request) -> Self::Future {
@@ -82,7 +82,6 @@ impl<A, B, Request> Future for AndThenFuture<A, B, Request>
8282
where
8383
A: Service<Request>,
8484
B: Service<A::Response, Error = A::Error>,
85-
B::Error: Into<A::Error>,
8685
{
8786
type Item = B::Response;
8887
type Error = A::Error;
@@ -94,7 +93,7 @@ where
9493

9594
match self.fut_a.poll() {
9695
Ok(Async::Ready(resp)) => {
97-
self.fut_b = Some(self.b.borrow_mut().call(resp));
96+
self.fut_b = Some(self.b.get_mut().call(resp));
9897
self.poll()
9998
}
10099
Ok(Async::NotReady) => Ok(Async::NotReady),
@@ -219,7 +218,7 @@ mod tests {
219218
use std::rc::Rc;
220219

221220
use super::*;
222-
use crate::service::{NewServiceExt, Service, ServiceExt};
221+
use crate::{NewService, Service};
223222

224223
struct Srv1(Rc<Cell<usize>>);
225224
impl Service<&'static str> for Srv1 {
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ where
5050
F: Fn(In, &mut T) -> Out,
5151
Out: IntoFuture,
5252
{
53-
type Response = <Out::Future as Future>::Item;
54-
type Error = <Out::Future as Future>::Error;
53+
type Response = Out::Item;
54+
type Error = Out::Error;
5555
type Future = Out::Future;
5656

5757
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
@@ -110,8 +110,8 @@ where
110110
F: Fn(In, &mut T::Service) -> Out + Clone,
111111
Out: IntoFuture,
112112
{
113-
type Response = <Out::Future as Future>::Item;
114-
type Error = <Out::Future as Future>::Error;
113+
type Response = Out::Item;
114+
type Error = Out::Error;
115115
type Service = Apply<T::Service, F, In, Out, Request>;
116116

117117
type InitError = T::InitError;
@@ -171,9 +171,7 @@ mod tests {
171171
use futures::future::{ok, FutureResult};
172172
use futures::{Async, Future, Poll};
173173

174-
use crate::service::{
175-
IntoNewService, IntoService, NewService, NewServiceExt, Service, ServiceExt,
176-
};
174+
use crate::{IntoNewService, IntoService, NewService, Service};
177175

178176
#[derive(Clone)]
179177
struct Srv;

actix-service/src/cell.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//! Custom cell impl
2+
use std::{cell::UnsafeCell, fmt, rc::Rc};
3+
4+
pub(crate) struct Cell<T> {
5+
inner: Rc<UnsafeCell<T>>,
6+
}
7+
8+
impl<T> Clone for Cell<T> {
9+
fn clone(&self) -> Self {
10+
Self {
11+
inner: self.inner.clone(),
12+
}
13+
}
14+
}
15+
16+
impl<T: fmt::Debug> fmt::Debug for Cell<T> {
17+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18+
self.inner.fmt(f)
19+
}
20+
}
21+
22+
impl<T> Cell<T> {
23+
pub(crate) fn new(inner: T) -> Self {
24+
Self {
25+
inner: Rc::new(UnsafeCell::new(inner)),
26+
}
27+
}
28+
29+
pub(crate) fn get_mut(&mut self) -> &mut T {
30+
unsafe { &mut *self.inner.as_ref().get() }
31+
}
32+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ mod tests {
159159
use futures::future::{err, FutureResult};
160160

161161
use super::*;
162-
use crate::service::{IntoNewService, NewServiceExt, Service, ServiceExt};
162+
use crate::{IntoNewService, NewService, Service};
163163

164164
struct Srv;
165165
impl Service<()> for Srv {

0 commit comments

Comments
 (0)