Skip to content

Commit d45e6a0

Browse files
jplattehawkwdavidbarsky
committed
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 <[email protected]> Co-authored-by: David Barsky <[email protected]>
1 parent 9320937 commit d45e6a0

File tree

5 files changed

+48
-32
lines changed

5 files changed

+48
-32
lines changed

tracing-futures/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ license = "MIT"
2121
default = ["std-future", "std"]
2222
futures-01 = ["futures_01", "std"]
2323
futures-03 = ["std-future", "futures", "futures-task", "std"]
24-
std-future = ["pin-project"]
24+
std-future = ["pin-project-lite"]
2525
std = ["tracing/std"]
2626

2727
[dependencies]
2828
futures_01 = { package = "futures", version = "0.1", optional = true }
2929
futures = { version = "0.3.0", optional = true }
3030
futures-task = { version = "0.3", optional = true }
31-
pin-project = { version = "1.0", optional = true }
31+
pin-project-lite = { version = "0.2.4", optional = true }
3232
tracing = { path = "../tracing", version = "0.1", default-features = false }
3333
tokio-executor = { version = "0.1", optional = true }
3434
tokio = { version = "0.1", optional = true }

tracing-futures/src/lib.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
#![cfg_attr(not(feature = "std"), no_std)]
104104
#![cfg_attr(docsrs, feature(doc_cfg), deny(broken_intra_doc_links))]
105105
#[cfg(feature = "std-future")]
106-
use pin_project::pin_project;
106+
use pin_project_lite::pin_project;
107107

108108
pub(crate) mod stdlib;
109109

@@ -242,30 +242,44 @@ pub trait WithSubscriber: Sized {
242242
}
243243
}
244244

245+
#[cfg(feature = "std-future")]
246+
pin_project! {
247+
/// A future, stream, sink, or executor that has been instrumented with a `tracing` span.
248+
#[derive(Debug, Clone)]
249+
pub struct Instrumented<T> {
250+
#[pin]
251+
inner: T,
252+
span: Span,
253+
}
254+
}
255+
245256
/// A future, stream, sink, or executor that has been instrumented with a `tracing` span.
246-
#[cfg_attr(feature = "std-future", pin_project)]
257+
#[cfg(not(feature = "std-future"))]
247258
#[derive(Debug, Clone)]
248259
pub struct Instrumented<T> {
249-
#[cfg(feature = "std-future")]
250-
#[pin]
251-
inner: T,
252-
#[cfg(not(feature = "std-future"))]
253260
inner: T,
254261
span: Span,
255262
}
256263

264+
#[cfg(all(feature = "std", feature = "std-future"))]
265+
pin_project! {
266+
/// A future, stream, sink, or executor that has been instrumented with a
267+
/// `tracing` subscriber.
268+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
269+
#[derive(Clone, Debug)]
270+
pub struct WithDispatch<T> {
271+
#[pin]
272+
inner: T,
273+
dispatch: Dispatch,
274+
}
275+
}
276+
257277
/// A future, stream, sink, or executor that has been instrumented with a
258278
/// `tracing` subscriber.
259-
#[cfg(feature = "std")]
279+
#[cfg(all(feature = "std", not(feature = "std-future")))]
260280
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
261-
#[cfg_attr(feature = "std-future", pin_project)]
262281
#[derive(Clone, Debug)]
263282
pub struct WithDispatch<T> {
264-
// cfg_attr doesn't work inside structs, apparently...
265-
#[cfg(feature = "std-future")]
266-
#[pin]
267-
inner: T,
268-
#[cfg(not(feature = "std-future"))]
269283
inner: T,
270284
dispatch: Dispatch,
271285
}

tracing-tower/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ license = "MIT"
2020
default = ["tower-layer", "tower-make", "http"]
2121
tower-make = [
2222
"tower_make",
23-
"pin-project",
23+
"pin-project-lite",
2424
]
2525

2626
[dependencies]
@@ -30,7 +30,7 @@ futures = "0.3"
3030
tower-service = "0.3"
3131
tower-layer = { version = "0.3", optional = true }
3232
tower_make = { package = "tower-make", version = "0.3", optional = true }
33-
pin-project = { version = "1.0", optional = true }
33+
pin-project-lite = { version = "0.2.4", optional = true }
3434
http = { version = "0.2", optional = true }
3535

3636
[badges]

tracing-tower/src/request_span.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub use self::make::MakeService;
7979
#[cfg_attr(docsrs, doc(cfg(feature = "tower-make")))]
8080
pub mod make {
8181
use super::*;
82-
use pin_project::pin_project;
82+
use pin_project_lite::pin_project;
8383

8484
#[derive(Debug)]
8585
pub struct MakeService<S, R, G = fn(&R) -> tracing::Span> {
@@ -99,13 +99,14 @@ pub mod make {
9999
_p: PhantomData<fn(T, R)>,
100100
}
101101

102-
#[pin_project]
103-
#[derive(Debug)]
104-
pub struct MakeFuture<F, R, G = fn(&R) -> tracing::Span> {
105-
get_span: Option<G>,
106-
#[pin]
107-
inner: F,
108-
_p: PhantomData<fn(R)>,
102+
pin_project! {
103+
#[derive(Debug)]
104+
pub struct MakeFuture<F, R, G = fn(&R) -> tracing::Span> {
105+
get_span: Option<G>,
106+
#[pin]
107+
inner: F,
108+
_p: PhantomData<fn(R)>,
109+
}
109110
}
110111

111112
#[cfg(feature = "tower-layer")]

tracing-tower/src/service_span.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ mod layer {
7979
#[cfg_attr(docsrs, doc(cfg(feature = "tower-layer")))]
8080
pub mod make {
8181
use super::*;
82-
use pin_project::pin_project;
82+
use pin_project_lite::pin_project;
8383

8484
#[derive(Debug)]
8585
pub struct MakeService<M, T, R, G = fn(&T) -> tracing::Span>
@@ -91,12 +91,13 @@ pub mod make {
9191
_p: PhantomData<fn(T, R)>,
9292
}
9393

94-
#[pin_project]
95-
#[derive(Debug)]
96-
pub struct MakeFuture<F> {
97-
#[pin]
98-
inner: F,
99-
span: Option<tracing::Span>,
94+
pin_project! {
95+
#[derive(Debug)]
96+
pub struct MakeFuture<F> {
97+
#[pin]
98+
inner: F,
99+
span: Option<tracing::Span>,
100+
}
100101
}
101102

102103
#[derive(Debug)]

0 commit comments

Comments
 (0)