Skip to content

Commit

Permalink
move service to separate crate
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Dec 9, 2018
1 parent e8aa73a commit 5f37d85
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 74 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ matrix:

env:
global:
# - RUSTFLAGS="-C link-dead-code"
- RUSTFLAGS="-C link-dead-code"
- OPENSSL_VERSION=openssl-1.0.2

before_install:
Expand All @@ -33,13 +33,15 @@ script:
if [[ "$TRAVIS_RUST_VERSION" != "nightly" ]]; then
cargo clean
cargo test --features="ssl,tls,rust-tls" -- --nocapture
cd actix-service && cargo test
fi
- |
if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then
RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install -f cargo-tarpaulin
cargo tarpaulin --features="ssl,tls,rust-tls" --out Xml
bash <(curl -s https://codecov.io/bash)
echo "Uploaded code coverage"
cd actix-service && cargo tarpaulin --out Xml && bash <(curl -s https://codecov.io/bash)
fi
# Upload docs
Expand Down
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ license = "MIT/Apache-2.0"
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"]
edition = "2018"

[workspace]
members = [
"./",
"actix-service",
]

[package.metadata.docs.rs]
features = ["ssl", "tls", "rust-tls"]

Expand Down Expand Up @@ -41,6 +47,8 @@ cell = []

[dependencies]
actix = "0.7.6"
# actix-service = "0.1"
actix-service = { path="./actix-service" }

log = "0.4"
num_cpus = "1.0"
Expand Down
26 changes: 26 additions & 0 deletions actix-service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "actix-service"
version = "0.1.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix Service"
keywords = ["network", "framework", "async", "futures"]
homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-net.git"
documentation = "https://docs.rs/actix-service/"
categories = ["network-programming", "asynchronous"]
license = "MIT/Apache-2.0"
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"]
edition = "2018"
workspace = "../"

[badges]
travis-ci = { repository = "actix/actix-service", branch = "master" }
# appveyor = { repository = "fafhrd91/actix-web-hdy9d" }
codecov = { repository = "actix/actix-service", branch = "master", service = "github" }

[lib]
name = "actix_service"
path = "src/lib.rs"

[dependencies]
futures = "0.1.24"
7 changes: 3 additions & 4 deletions src/service/and_then.rs → actix-service/src/and_then.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ where

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

fn call(&mut self, req: Request) -> Self::Future {
Expand Down Expand Up @@ -82,7 +82,6 @@ impl<A, B, Request> Future for AndThenFuture<A, B, Request>
where
A: Service<Request>,
B: Service<A::Response, Error = A::Error>,
B::Error: Into<A::Error>,
{
type Item = B::Response;
type Error = A::Error;
Expand All @@ -94,7 +93,7 @@ where

match self.fut_a.poll() {
Ok(Async::Ready(resp)) => {
self.fut_b = Some(self.b.borrow_mut().call(resp));
self.fut_b = Some(self.b.get_mut().call(resp));
self.poll()
}
Ok(Async::NotReady) => Ok(Async::NotReady),
Expand Down Expand Up @@ -219,7 +218,7 @@ mod tests {
use std::rc::Rc;

use super::*;
use crate::service::{NewServiceExt, Service, ServiceExt};
use crate::{NewService, Service};

struct Srv1(Rc<Cell<usize>>);
impl Service<&'static str> for Srv1 {
Expand Down
12 changes: 5 additions & 7 deletions src/service/apply.rs → actix-service/src/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ where
F: Fn(In, &mut T) -> Out,
Out: IntoFuture,
{
type Response = <Out::Future as Future>::Item;
type Error = <Out::Future as Future>::Error;
type Response = Out::Item;
type Error = Out::Error;
type Future = Out::Future;

fn poll_ready(&mut self) -> Poll<(), Self::Error> {
Expand Down Expand Up @@ -110,8 +110,8 @@ where
F: Fn(In, &mut T::Service) -> Out + Clone,
Out: IntoFuture,
{
type Response = <Out::Future as Future>::Item;
type Error = <Out::Future as Future>::Error;
type Response = Out::Item;
type Error = Out::Error;
type Service = Apply<T::Service, F, In, Out, Request>;

type InitError = T::InitError;
Expand Down Expand Up @@ -171,9 +171,7 @@ mod tests {
use futures::future::{ok, FutureResult};
use futures::{Async, Future, Poll};

use crate::service::{
IntoNewService, IntoService, NewService, NewServiceExt, Service, ServiceExt,
};
use crate::{IntoNewService, IntoService, NewService, Service};

#[derive(Clone)]
struct Srv;
Expand Down
32 changes: 32 additions & 0 deletions actix-service/src/cell.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! Custom cell impl
use std::{cell::UnsafeCell, fmt, rc::Rc};

pub(crate) struct Cell<T> {
inner: Rc<UnsafeCell<T>>,
}

impl<T> Clone for Cell<T> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
}
}
}

impl<T: fmt::Debug> fmt::Debug for Cell<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.inner.fmt(f)
}
}

impl<T> Cell<T> {
pub(crate) fn new(inner: T) -> Self {
Self {
inner: Rc::new(UnsafeCell::new(inner)),
}
}

pub(crate) fn get_mut(&mut self) -> &mut T {
unsafe { &mut *self.inner.as_ref().get() }
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/service/from_err.rs → actix-service/src/from_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ mod tests {
use futures::future::{err, FutureResult};

use super::*;
use crate::service::{IntoNewService, NewServiceExt, Service, ServiceExt};
use crate::{IntoNewService, NewService, Service};

struct Srv;
impl Service<()> for Srv {
Expand Down

0 comments on commit 5f37d85

Please sign in to comment.