`Pin<_>` errors on tokio::try_join
pauliesnug opened this issue · comments
Version
│ ├── tokio v1.36.0
│ │ └── tokio-macros v2.2.0 (proc-macro)
│ ├── tokio-native-tls v0.3.1
│ │ └── tokio v1.36.0 (*)
│ │ │ ├── tokio v1.36.0 (*)
│ │ │ ├── tokio-util v0.7.10
│ │ │ │ ├── tokio v1.36.0 (*)
│ │ │ ├── tokio v1.36.0 (*)
│ │ │ │ ├── tokio v1.36.0 (*)
│ │ │ │ │ ├── tokio v1.36.0 (*)
│ │ │ ├── tokio v1.36.0 (*)
│ │ │ ├── tokio-native-tls v0.3.1 (*)
│ │ ├── tokio v1.36.0 (*)
│ │ ├── tokio-native-tls v0.3.1 (*)
│ │ ├── tokio-util v0.7.10 (*)
│ └── tokio v1.36.0 (*)
│ │ │ ├── tokio v1.36.0 (*)
│ │ │ ├── tokio-util v0.7.10 (*)
│ │ │ ├── tokio v1.36.0 (*)
│ │ ├── tokio v1.36.0 (*)
│ │ ├── tokio-util v0.7.10 (*)
│ ├── tokio v1.36.0 (*)
├── tokio v1.36.0 (*)
├── tokio-stream v0.1.15
│ └── tokio v1.36.0 (*)
├── tokio v1.36.0 (*)
└── tokio v1.36.0 (*)
Platform
MacOS Sonoma 14.4.1
Description
I am trying to make a wrapper over tokio::try_join!
, which accepts multiple async outputs that are awaited on with custom logic and then added to the try_join! block.
I tried this code:
#[macro_export]
macro_rules! tokio_test {
() => {
{
paste::paste! {
tokio::try_join! (
$( [ <name $task>] ),+
)
}
}
}
}
I expected to see this happen: All async tasks would be added and run in the try_join! block with no errors.
Instead, this happened: I recieved two errors, one type annotations needed
at try_join.rs:(174, 93)
, and another no method named
take_outputfound for struct
Pin<>in the current scope method not found in
Pin<>`` error at try_join.rs(196, 26)
.
Your current example doesn't invoke the macro, so it does not trigger the error. Please provide a more complete reproducer.
I tried using what you gave me, but it fails with unrelated errors:
Compiling playground v0.0.1 (/playground)
error: expected expression, found `$`
--> src/main.rs:7:29
|
7 | let increment = $total / num_futures as f64;
| ^^^^^^ expected expression
...
34 | let (clusters, users) = tokio_test! {
| _________________________________-
35 | | Some("loading core features");
36 | | clusters_in,
37 | | users_in,
38 | | }?;
| |_________- in this macro invocation
|
= note: this error originates in the macro `tokio_test` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: could not find `count` in the crate root
--> src/main.rs:6:39
|
6 | let num_futures = $crate::count!($($task)*);
| ^^^^^ could not find `count` in the crate root
...
34 | let (clusters, users) = tokio_test! {
| _________________________________-
35 | | Some("loading core features");
36 | | clusters_in,
37 | | users_in,
38 | | }?;
| |_________- in this macro invocation
|
= note: this error originates in the macro `tokio_test` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
--> src/main.rs:33:5
|
32 | async fn main() {
| - expected `()` because of default return type
33 | / Box::pin(async move {
34 | | let (clusters, users) = tokio_test! {
35 | | Some("loading core features");
36 | | clusters_in,
37 | | users_in,
38 | | }?;
39 | | })
| |______^ expected `()`, found `Pin<Box<...>>`
|
= note: expected unit type `()`
found struct `Pin<Box<{async block@src/main.rs:33:14: 39:6}>>`
Some errors have detailed explanations: E0308, E0433.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `playground` (bin "playground") due to 3 previous errors
I can't tell what the problem is from just looking at your code, so I really need a complete example that I can run myself. Without code that I can run and tweak myself, I can't help you.