Skip to content

Commit e31f5cc

Browse files
authored
chore: Replace tokio::pin with std::pin::pin (#1593)
1 parent ea8cd3f commit e31f5cc

File tree

5 files changed

+18
-26
lines changed

5 files changed

+18
-26
lines changed

tonic/Cargo.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ gzip = ["dep:flate2"]
2828
zstd = ["dep:zstd"]
2929
default = ["transport", "codegen", "prost"]
3030
prost = ["dep:prost"]
31-
tls = ["dep:rustls-pki-types", "dep:rustls-pemfile", "transport", "dep:tokio-rustls", "tokio/rt", "tokio/macros"]
31+
tls = ["dep:rustls-pki-types", "dep:rustls-pemfile", "transport", "dep:tokio-rustls", "dep:tokio", "tokio?/rt", "tokio?/macros"]
3232
tls-roots = ["tls-roots-common", "dep:rustls-native-certs"]
3333
tls-roots-common = ["tls"]
3434
tls-webpki-roots = ["tls-roots-common", "dep:webpki-roots"]
@@ -38,8 +38,7 @@ transport = [
3838
"channel",
3939
"dep:h2",
4040
"dep:hyper",
41-
"tokio/net",
42-
"tokio/time",
41+
"dep:tokio", "tokio?/net", "tokio?/time",
4342
"dep:tower",
4443
"dep:hyper-timeout",
4544
]
@@ -55,7 +54,6 @@ bytes = "1.0"
5554
http = "0.2"
5655
tracing = "0.1"
5756

58-
tokio = "1.0.1"
5957
http-body = "0.4.4"
6058
percent-encoding = "2.1"
6159
pin-project = "1.0.11"
@@ -72,6 +70,7 @@ async-trait = {version = "0.1.13", optional = true}
7270
h2 = {version = "0.3.24", optional = true}
7371
hyper = {version = "0.14.26", features = ["full"], optional = true}
7472
hyper-timeout = {version = "0.4", optional = true}
73+
tokio = {version = "1.0.1", optional = true}
7574
tokio-stream = "0.1"
7675
tower = {version = "0.4.7", default-features = false, features = ["balance", "buffer", "discover", "limit", "load", "make", "timeout", "util"], optional = true}
7776
axum = {version = "0.6.9", default_features = false, optional = true}

tonic/src/client/grpc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use http::{
1111
uri::{PathAndQuery, Uri},
1212
};
1313
use http_body::Body;
14-
use std::{fmt, future};
14+
use std::{fmt, future, pin::pin};
1515
use tokio_stream::{Stream, StreamExt};
1616

1717
/// A gRPC client dispatcher.
@@ -239,7 +239,7 @@ impl<T> Grpc<T> {
239239
let (mut parts, body, extensions) =
240240
self.streaming(request, path, codec).await?.into_parts();
241241

242-
tokio::pin!(body);
242+
let mut body = pin!(body);
243243

244244
let message = body
245245
.try_next()

tonic/src/codec/prost.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ mod tests {
8484
use crate::{Code, Status};
8585
use bytes::{Buf, BufMut, BytesMut};
8686
use http_body::Body;
87+
use std::pin::pin;
8788

8889
const LEN: usize = 10000;
8990
// The maximum uncompressed size in bytes for a message. Set to 2MB.
@@ -157,15 +158,13 @@ mod tests {
157158
let messages = std::iter::repeat_with(move || Ok::<_, Status>(msg.clone())).take(10000);
158159
let source = tokio_stream::iter(messages);
159160

160-
let body = encode_server(
161+
let mut body = pin!(encode_server(
161162
encoder,
162163
source,
163164
None,
164165
SingleMessageCompressionOverride::default(),
165166
None,
166-
);
167-
168-
tokio::pin!(body);
167+
));
169168

170169
while let Some(r) = body.data().await {
171170
r.unwrap();
@@ -181,15 +180,13 @@ mod tests {
181180
let messages = std::iter::once(Ok::<_, Status>(msg));
182181
let source = tokio_stream::iter(messages);
183182

184-
let body = encode_server(
183+
let mut body = pin!(encode_server(
185184
encoder,
186185
source,
187186
None,
188187
SingleMessageCompressionOverride::default(),
189188
Some(MAX_MESSAGE_SIZE),
190-
);
191-
192-
tokio::pin!(body);
189+
));
193190

194191
assert!(body.data().await.is_none());
195192
assert_eq!(
@@ -215,15 +212,13 @@ mod tests {
215212
let messages = std::iter::once(Ok::<_, Status>(msg));
216213
let source = tokio_stream::iter(messages);
217214

218-
let body = encode_server(
215+
let mut body = pin!(encode_server(
219216
encoder,
220217
source,
221218
None,
222219
SingleMessageCompressionOverride::default(),
223220
Some(usize::MAX),
224-
);
225-
226-
tokio::pin!(body);
221+
));
227222

228223
assert!(body.data().await.is_none());
229224
assert_eq!(

tonic/src/server/grpc.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
Code, Request, Status,
99
};
1010
use http_body::Body;
11-
use std::fmt;
11+
use std::{fmt, pin::pin};
1212
use tokio_stream::{Stream, StreamExt};
1313

1414
macro_rules! t {
@@ -375,14 +375,12 @@ where
375375

376376
let (parts, body) = request.into_parts();
377377

378-
let stream = Streaming::new_request(
378+
let mut stream = pin!(Streaming::new_request(
379379
self.codec.decoder(),
380380
body,
381381
request_compression_encoding,
382382
self.max_decoding_message_size,
383-
);
384-
385-
tokio::pin!(stream);
383+
));
386384

387385
let message = stream
388386
.try_next()

tonic/src/transport/server/incoming.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use hyper::server::{
66
};
77
use std::{
88
net::SocketAddr,
9-
pin::Pin,
9+
pin::{pin, Pin},
1010
task::{Context, Poll},
1111
time::Duration,
1212
};
@@ -26,7 +26,7 @@ where
2626
IE: Into<crate::Error>,
2727
{
2828
async_stream::try_stream! {
29-
tokio::pin!(incoming);
29+
let mut incoming = pin!(incoming);
3030

3131
while let Some(item) = incoming.next().await {
3232
yield item.map(ServerIo::new_io)?
@@ -44,7 +44,7 @@ where
4444
IE: Into<crate::Error>,
4545
{
4646
async_stream::try_stream! {
47-
tokio::pin!(incoming);
47+
let mut incoming = pin!(incoming);
4848

4949
let mut tasks = tokio::task::JoinSet::new();
5050

0 commit comments

Comments
 (0)