Skip to content

Commit 4d31bbb

Browse files
committed
fixup! chore: replace all doctest usage of pin_mut with pin
Signed-off-by: tison <[email protected]>
1 parent 0165381 commit 4d31bbb

File tree

9 files changed

+67
-45
lines changed

9 files changed

+67
-45
lines changed

futures-util/src/async_await/select_mod.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ macro_rules! document_select_macro {
5858
/// select! {
5959
/// x = st.next() => assert_eq!(Some(2), x),
6060
/// _ = fut => panic!(),
61-
/// };
61+
/// }
6262
/// # });
6363
/// ```
6464
///
@@ -87,14 +87,15 @@ macro_rules! document_select_macro {
8787
/// If a similar async function is called outside of `select` to produce
8888
/// a `Future`, the `Future` must be pinned in order to be able to pass
8989
/// it to `select`. This can be achieved via `Box::pin` for pinning a
90-
/// `Future` on the heap or the `pin_mut!` macro for pinning a `Future`
90+
/// `Future` on the heap or the `pin!` macro for pinning a `Future`
9191
/// on the stack.
9292
///
9393
/// ```
9494
/// # futures::executor::block_on(async {
95+
/// use core::pin::pin;
96+
///
9597
/// use futures::future::FutureExt;
9698
/// use futures::select;
97-
/// use futures::pin_mut;
9899
///
99100
/// // Calling the following async fn returns a Future which does not
100101
/// // implement Unpin
@@ -105,7 +106,7 @@ macro_rules! document_select_macro {
105106
/// let fut_1 = async_identity_fn(1).fuse();
106107
/// let fut_2 = async_identity_fn(2).fuse();
107108
/// let mut fut_1 = Box::pin(fut_1); // Pins the Future on the heap
108-
/// pin_mut!(fut_2); // Pins the Future on the stack
109+
/// let mut fut_2 = pin!(fut_2); // Pins the Future on the stack
109110
///
110111
/// let res = select! {
111112
/// a_res = fut_1 => a_res,
@@ -138,7 +139,7 @@ macro_rules! document_select_macro {
138139
/// b = b_fut => total += b,
139140
/// complete => break,
140141
/// default => panic!(), // never runs (futures run first, then complete)
141-
/// };
142+
/// }
142143
/// }
143144
/// assert_eq!(total, 10);
144145
/// # });
@@ -209,7 +210,7 @@ macro_rules! document_select_macro {
209210
/// select_biased! {
210211
/// x = st.next() => assert_eq!(Some(2), x),
211212
/// _ = fut => panic!(),
212-
/// };
213+
/// }
213214
/// # });
214215
/// ```
215216
///
@@ -238,14 +239,15 @@ macro_rules! document_select_macro {
238239
/// If a similar async function is called outside of `select_biased` to produce
239240
/// a `Future`, the `Future` must be pinned in order to be able to pass
240241
/// it to `select_biased`. This can be achieved via `Box::pin` for pinning a
241-
/// `Future` on the heap or the `pin_mut!` macro for pinning a `Future`
242+
/// `Future` on the heap or the `pin!` macro for pinning a `Future`
242243
/// on the stack.
243244
///
244245
/// ```
245246
/// # futures::executor::block_on(async {
247+
/// use core::pin::pin;
248+
///
246249
/// use futures::future::FutureExt;
247250
/// use futures::select_biased;
248-
/// use futures::pin_mut;
249251
///
250252
/// // Calling the following async fn returns a Future which does not
251253
/// // implement Unpin
@@ -256,7 +258,7 @@ macro_rules! document_select_macro {
256258
/// let fut_1 = async_identity_fn(1).fuse();
257259
/// let fut_2 = async_identity_fn(2).fuse();
258260
/// let mut fut_1 = Box::pin(fut_1); // Pins the Future on the heap
259-
/// pin_mut!(fut_2); // Pins the Future on the stack
261+
/// let mut fut_2 = pin!(fut_2); // Pins the Future on the stack
260262
///
261263
/// let res = select_biased! {
262264
/// a_res = fut_1 => a_res,
@@ -289,7 +291,7 @@ macro_rules! document_select_macro {
289291
/// b = b_fut => total += b,
290292
/// complete => break,
291293
/// default => panic!(), // never runs (futures run first, then complete)
292-
/// };
294+
/// }
293295
/// }
294296
/// assert_eq!(total, 10);
295297
/// # });

futures-util/src/future/future/fuse.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ impl<Fut: Future> Fuse<Fut> {
2929
///
3030
/// ```
3131
/// # futures::executor::block_on(async {
32+
/// use core::pin::pin;
33+
///
3234
/// use futures::channel::mpsc;
3335
/// use futures::future::{Fuse, FusedFuture, FutureExt};
3436
/// use futures::select;
3537
/// use futures::stream::StreamExt;
36-
/// use futures::pin_mut;
3738
///
3839
/// let (sender, mut stream) = mpsc::unbounded();
3940
///
@@ -45,7 +46,7 @@ impl<Fut: Future> Fuse<Fut> {
4546
/// // Use `Fuse::terminated()` to create an already-terminated future
4647
/// // which may be instantiated later.
4748
/// let foo_printer = Fuse::terminated();
48-
/// pin_mut!(foo_printer);
49+
/// let mut foo_printer = pin!(foo_printer);
4950
///
5051
/// loop {
5152
/// select! {

futures-util/src/future/maybe_done.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ impl<Fut: Future + Unpin> Unpin for MaybeDone<Fut> {}
2929
///
3030
/// ```
3131
/// # futures::executor::block_on(async {
32+
/// use core::pin::pin;
33+
///
3234
/// use futures::future;
33-
/// use futures::pin_mut;
3435
///
3536
/// let future = future::maybe_done(async { 5 });
36-
/// pin_mut!(future);
37+
/// let mut future = pin!(future);
3738
/// assert_eq!(future.as_mut().take_output(), None);
3839
/// let () = future.as_mut().await;
3940
/// assert_eq!(future.as_mut().take_output(), Some(5));

futures-util/src/future/poll_immediate.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ impl<T: Future> FusedFuture for PollImmediate<T> {
4848
/// so polling it in a tight loop is worse than using a blocking synchronous function.
4949
/// ```
5050
/// # futures::executor::block_on(async {
51+
/// use core::pin::pin;
52+
///
5153
/// use futures::task::Poll;
52-
/// use futures::{StreamExt, future, pin_mut};
54+
/// use futures::{StreamExt, future};
5355
/// use future::FusedFuture;
5456
///
5557
/// let f = async { 1_u32 };
56-
/// pin_mut!(f);
58+
/// let mut f = pin!(f);
5759
/// let mut r = future::poll_immediate(f);
5860
/// assert_eq!(r.next().await, Some(Poll::Ready(1)));
5961
///
6062
/// let f = async {futures::pending!(); 42_u8};
61-
/// pin_mut!(f);
63+
/// let mut f = pin!(f);
6264
/// let mut p = future::poll_immediate(f);
6365
/// assert_eq!(p.next().await, Some(Poll::Pending));
6466
/// assert!(!p.is_terminated());
@@ -114,9 +116,12 @@ where
114116
///
115117
/// ```
116118
/// # futures::executor::block_on(async {
117-
/// use futures::{future, pin_mut};
119+
/// use core::pin::pin;
120+
///
121+
/// use futures::future;
122+
///
118123
/// let f = async {futures::pending!(); 42_u8};
119-
/// pin_mut!(f);
124+
/// let mut f = pin!(f);
120125
/// assert_eq!(None, future::poll_immediate(&mut f).await);
121126
/// assert_eq!(42, f.await);
122127
/// # });

futures-util/src/future/select.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ impl<A: Unpin, B: Unpin> Unpin for Select<A, B> {}
3232
///
3333
/// ```
3434
/// # futures::executor::block_on(async {
35-
/// use futures::{
36-
/// pin_mut,
37-
/// future::Either,
38-
/// future::self,
39-
/// };
35+
/// use core::pin::pin;
36+
///
37+
/// use futures::future;
38+
/// use futures::future::Either;
4039
///
4140
/// // These two futures have different types even though their outputs have the same type.
4241
/// let future1 = async {
@@ -48,8 +47,8 @@ impl<A: Unpin, B: Unpin> Unpin for Select<A, B> {}
4847
/// };
4948
///
5049
/// // 'select' requires Future + Unpin bounds
51-
/// pin_mut!(future1);
52-
/// pin_mut!(future2);
50+
/// let mut future1 = pin!(future1);
51+
/// let mut future2 = pin!(future2);
5352
///
5453
/// let value = match future::select(future1, future2).await {
5554
/// Either::Left((value1, _)) => value1, // `value1` is resolved from `future1`

futures-util/src/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
/// # Example
1010
///
1111
/// ```rust
12-
/// # use futures_util::pin_mut;
12+
/// # use core::pin::pin;
1313
/// # use core::pin::Pin;
1414
/// # struct Foo {}
1515
/// let foo = Foo { /* ... */ };
16-
/// pin_mut!(foo);
16+
/// let foo = pin!(foo);
1717
/// let _: Pin<&mut Foo> = foo;
1818
/// ```
1919
#[macro_export]

futures-util/src/sink/unfold.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ pin_project! {
2323
///
2424
/// ```
2525
/// # futures::executor::block_on(async {
26-
/// use futures::sink::{self, SinkExt};
26+
/// use core::pin::pin;
27+
///
28+
/// use futures::sink;
29+
/// use futures::sink::SinkExt;
2730
///
2831
/// let unfold = sink::unfold(0, |mut sum, i: i32| {
2932
/// async move {
@@ -32,7 +35,7 @@ pin_project! {
3235
/// Ok::<_, std::convert::Infallible>(sum)
3336
/// }
3437
/// });
35-
/// futures::pin_mut!(unfold);
38+
/// let mut unfold = pin!(unfold);
3639
/// unfold.send(5).await?;
3740
/// # Ok::<(), std::convert::Infallible>(()) }).unwrap();
3841
/// ```

futures-util/src/stream/stream/peek.rs

+20-12
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ impl<St: Stream> Peekable<St> {
6464
///
6565
/// ```
6666
/// # futures::executor::block_on(async {
67-
/// use futures::stream::{self, StreamExt};
68-
/// use futures::pin_mut;
67+
/// use core::pin::pin;
68+
///
69+
/// use futures::stream;
70+
/// use futures::stream::StreamExt;
6971
///
7072
/// let stream = stream::iter(vec![1, 2, 3]).peekable();
71-
/// pin_mut!(stream);
73+
/// let mut stream = pin!(stream);
7274
///
7375
/// assert_eq!(stream.as_mut().peek_mut().await, Some(&mut 1));
7476
/// assert_eq!(stream.as_mut().next().await, Some(1));
@@ -117,11 +119,13 @@ impl<St: Stream> Peekable<St> {
117119
///
118120
/// ```
119121
/// # futures::executor::block_on(async {
120-
/// use futures::stream::{self, StreamExt};
121-
/// use futures::pin_mut;
122+
/// use core::pin::pin;
123+
///
124+
/// use futures::stream;
125+
/// use futures::stream::StreamExt;
122126
///
123127
/// let stream = stream::iter(0..5).peekable();
124-
/// pin_mut!(stream);
128+
/// let mut stream = pin!(stream);
125129
/// // The first item of the stream is 0; consume it.
126130
/// assert_eq!(stream.as_mut().next_if(|&x| x == 0).await, Some(0));
127131
/// // The next item returned is now 1, so `consume` will return `false`.
@@ -135,11 +139,13 @@ impl<St: Stream> Peekable<St> {
135139
///
136140
/// ```
137141
/// # futures::executor::block_on(async {
138-
/// use futures::stream::{self, StreamExt};
139-
/// use futures::pin_mut;
142+
/// use core::pin::pin;
143+
///
144+
/// use futures::stream;
145+
/// use futures::stream::StreamExt;
140146
///
141147
/// let stream = stream::iter(1..20).peekable();
142-
/// pin_mut!(stream);
148+
/// let mut stream = pin!(stream);
143149
/// // Consume all numbers less than 10
144150
/// while stream.as_mut().next_if(|&x| x < 10).await.is_some() {}
145151
/// // The next value returned will be 10
@@ -162,11 +168,13 @@ impl<St: Stream> Peekable<St> {
162168
///
163169
/// ```
164170
/// # futures::executor::block_on(async {
165-
/// use futures::stream::{self, StreamExt};
166-
/// use futures::pin_mut;
171+
/// use core::pin::pin;
172+
///
173+
/// use futures::stream;
174+
/// use futures::stream::StreamExt;
167175
///
168176
/// let stream = stream::iter(0..5).peekable();
169-
/// pin_mut!(stream);
177+
/// let mut stream = pin!(stream);
170178
/// // The first item of the stream is 0; consume it.
171179
/// assert_eq!(stream.as_mut().next_if_eq(&0).await, Some(0));
172180
/// // The next item returned is now 1, so `consume` will return `false`.

futures-util/src/stream/try_stream/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -657,16 +657,19 @@ pub trait TryStreamExt: TryStream {
657657
/// # Examples
658658
/// ```
659659
/// # futures::executor::block_on(async {
660-
/// use futures::stream::{self, StreamExt, TryStreamExt};
661-
/// use futures::pin_mut;
660+
/// use core::pin::pin;
661+
///
662+
/// use futures::stream;
663+
/// use futures::stream::StreamExt;
664+
/// use futures::stream::TryStreamExt;
662665
///
663666
/// let stream = stream::iter(vec![Ok(1i32), Ok(6i32), Err("error")]);
664667
/// let halves = stream.try_filter_map(|x| async move {
665668
/// let ret = if x % 2 == 0 { Some(x / 2) } else { None };
666669
/// Ok(ret)
667670
/// });
668671
///
669-
/// pin_mut!(halves);
672+
/// let mut halves = pin!(halves);
670673
/// assert_eq!(halves.next().await, Some(Ok(3)));
671674
/// assert_eq!(halves.next().await, Some(Err("error")));
672675
/// # })

0 commit comments

Comments
 (0)