Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove last dependency on pin-project #629

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions tower/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ retry = ["__common", "tokio/time"]
spawn-ready = ["__common", "futures-util", "tokio/sync", "tokio/rt", "util", "tracing"]
steer = []
timeout = ["pin-project-lite", "tokio/time"]
util = ["__common", "futures-util", "pin-project"]
util = ["__common", "futures-util"]

[dependencies]
tower-layer = { version = "0.3.1", path = "../tower-layer" }
Expand All @@ -78,7 +78,6 @@ tokio = { version = "1", optional = true, features = ["sync"] }
tokio-stream = { version = "0.1.0", optional = true }
tokio-util = { version = "0.6.3", default-features = false, optional = true }
tracing = { version = "0.1.2", default-features = false, features = ["std"], optional = true }
pin-project = { version = "1", optional = true }
pin-project-lite = { version = "0.2.7", optional = true }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion tower/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
rust_2018_idioms,
unreachable_pub
)]
#![forbid(unsafe_code)]
#![deny(unsafe_code)]
#![allow(elided_lifetimes_in_paths, clippy::type_complexity)]
#![cfg_attr(test, allow(clippy::float_cmp))]
#![cfg_attr(docsrs, feature(doc_cfg))]
Expand Down
23 changes: 19 additions & 4 deletions tower/src/util/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! See [`Either`] documentation for more details.

use futures_core::ready;
use pin_project::pin_project;
use std::{
future::Future,
pin::Pin,
Expand All @@ -17,13 +16,29 @@ use tower_service::Service;
/// Both services must be of the same request, response, and error types.
/// [`Either`] is useful for handling conditional branching in service middleware
/// to different inner service types.
#[pin_project(project = EitherProj)]
#[derive(Clone, Debug)]
pub enum Either<A, B> {
/// One type of backing [`Service`].
A(#[pin] A),
A(A),
/// The other type of backing [`Service`].
B(#[pin] B),
B(B),
}

impl<A, B> Either<A, B> {
#[allow(unsafe_code)] // pin-project-lite doesn't support tuple variants in enums
fn project(self: Pin<&mut Self>) -> EitherProj<'_, A, B> {
unsafe {
match self.get_unchecked_mut() {
Self::A(a) => EitherProj::A(Pin::new_unchecked(a)),
Self::B(b) => EitherProj::B(Pin::new_unchecked(b)),
}
}
}
}

enum EitherProj<'p, A, B> {
A(Pin<&'p mut A>),
B(Pin<&'p mut B>),
}

impl<A, B, Request> Service<Request> for Either<A, B>
Expand Down