tracing: Replace pin-project with pin-project-lite (#1185)

* futures: Replace pin-project by pin-project-lite
* tower: Replace pin-project by pin-project-lite

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: David Barsky <me@davidbarsky.com>
This commit is contained in:
Jonas Platte 2021-07-18 20:35:43 +02:00 committed by Eliza Weisman
parent aa589d9aec
commit f6157bb1fd
5 changed files with 48 additions and 32 deletions

View File

@ -21,14 +21,14 @@ license = "MIT"
default = ["std-future", "std"]
futures-01 = ["futures_01", "std"]
futures-03 = ["std-future", "futures", "futures-task", "std"]
std-future = ["pin-project"]
std-future = ["pin-project-lite"]
std = ["tracing/std"]
[dependencies]
futures_01 = { package = "futures", version = "0.1", optional = true }
futures = { version = "0.3.0", optional = true }
futures-task = { version = "0.3", optional = true }
pin-project = { version = "1.0", optional = true }
pin-project-lite = { version = "0.2.4", optional = true }
tracing = { path = "../tracing", version = "0.1", default-features = false }
tokio-executor = { version = "0.1", optional = true }
tokio = { version = "0.1", optional = true }

View File

@ -103,7 +103,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg), deny(broken_intra_doc_links))]
#[cfg(feature = "std-future")]
use pin_project::pin_project;
use pin_project_lite::pin_project;
pub(crate) mod stdlib;
@ -242,30 +242,44 @@ pub trait WithSubscriber: Sized {
}
}
#[cfg(feature = "std-future")]
pin_project! {
/// A future, stream, sink, or executor that has been instrumented with a `tracing` span.
#[derive(Debug, Clone)]
pub struct Instrumented<T> {
#[pin]
inner: T,
span: Span,
}
}
/// A future, stream, sink, or executor that has been instrumented with a `tracing` span.
#[cfg_attr(feature = "std-future", pin_project)]
#[cfg(not(feature = "std-future"))]
#[derive(Debug, Clone)]
pub struct Instrumented<T> {
#[cfg(feature = "std-future")]
#[pin]
inner: T,
#[cfg(not(feature = "std-future"))]
inner: T,
span: Span,
}
#[cfg(all(feature = "std", feature = "std-future"))]
pin_project! {
/// A future, stream, sink, or executor that has been instrumented with a
/// `tracing` subscriber.
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[derive(Clone, Debug)]
pub struct WithDispatch<T> {
#[pin]
inner: T,
dispatch: Dispatch,
}
}
/// A future, stream, sink, or executor that has been instrumented with a
/// `tracing` subscriber.
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(feature = "std-future")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[cfg_attr(feature = "std-future", pin_project)]
#[derive(Clone, Debug)]
pub struct WithDispatch<T> {
// cfg_attr doesn't work inside structs, apparently...
#[cfg(feature = "std-future")]
#[pin]
inner: T,
#[cfg(not(feature = "std-future"))]
inner: T,
dispatch: Dispatch,
}

View File

@ -20,7 +20,7 @@ license = "MIT"
default = ["tower-layer", "tower-make", "http"]
tower-make = [
"tower_make",
"pin-project",
"pin-project-lite",
]
[dependencies]
@ -30,7 +30,7 @@ futures = "0.3"
tower-service = "0.3"
tower-layer = { version = "0.3", optional = true }
tower_make = { package = "tower-make", version = "0.3", optional = true }
pin-project = { version = "1.0", optional = true }
pin-project-lite = { version = "0.2.4", optional = true }
http = { version = "0.2", optional = true }
[badges]

View File

@ -79,7 +79,7 @@ pub use self::make::MakeService;
#[cfg_attr(docsrs, doc(cfg(feature = "tower-make")))]
pub mod make {
use super::*;
use pin_project::pin_project;
use pin_project_lite::pin_project;
#[derive(Debug)]
pub struct MakeService<S, R, G = fn(&R) -> tracing::Span> {
@ -99,13 +99,14 @@ pub mod make {
_p: PhantomData<fn(T, R)>,
}
#[pin_project]
#[derive(Debug)]
pub struct MakeFuture<F, R, G = fn(&R) -> tracing::Span> {
get_span: Option<G>,
#[pin]
inner: F,
_p: PhantomData<fn(R)>,
pin_project! {
#[derive(Debug)]
pub struct MakeFuture<F, R, G = fn(&R) -> tracing::Span> {
get_span: Option<G>,
#[pin]
inner: F,
_p: PhantomData<fn(R)>,
}
}
#[cfg(feature = "tower-layer")]

View File

@ -79,7 +79,7 @@ mod layer {
#[cfg_attr(docsrs, doc(cfg(feature = "tower-layer")))]
pub mod make {
use super::*;
use pin_project::pin_project;
use pin_project_lite::pin_project;
#[derive(Debug)]
pub struct MakeService<M, T, R, G = fn(&T) -> tracing::Span>
@ -91,12 +91,13 @@ pub mod make {
_p: PhantomData<fn(T, R)>,
}
#[pin_project]
#[derive(Debug)]
pub struct MakeFuture<F> {
#[pin]
inner: F,
span: Option<tracing::Span>,
pin_project! {
#[derive(Debug)]
pub struct MakeFuture<F> {
#[pin]
inner: F,
span: Option<tracing::Span>,
}
}
#[derive(Debug)]