Open
Description
Using this rust version:
$ cargo --version
cargo 1.56.0-nightly (cc17afbb0 2021-08-02)
Given the following code:
use lazy_static::lazy_static;
use rand::distributions::{Distribution, Uniform};
use signal_hook::consts::signal::*;
use signal_hook_tokio::Signals;
use std::io::Error;
use std::time::Duration;
use tokio::time::{sleep, Instant};
lazy_static! {
static ref START_TIME: Instant = Instant::now();
}
async fn handle_signals(signals: Signals) {
let mut signals = signals.fuse();
while let Some(signal) = signals.next().await {
match signal {
SIGTERM | SIGINT | SIGQUIT => {
// Lets get out of here...
std::process::exit(1);
}
_ => unreachable!(),
}
}
}
#[tokio::main]
async fn main() -> Result<(), Error> {
let signals = Signals::new(&[SIGHUP, SIGTERM, SIGINT, SIGQUIT])?;
let handle = signals.handle();
let signals_task = tokio::spawn(handle_signals(signals));
let page = get_page(42).await;
println!("Page #42: {:?}", page);
// Terminate the signal stream.
handle.close();
signals_task.await?;
Ok(())
}
async fn get_page(i: usize) -> Vec<usize> {
let millis = Uniform::from(5_000..6_000).sample(&mut rand::thread_rng());
println!(
"[{}] # get_page({}) will complete in {} ms on {:?}",
START_TIME.elapsed().as_millis(),
i,
millis,
std::thread::current().id()
);
sleep(Duration::from_millis(millis)).await;
println!(
"[{}] # get_page({}) completed",
START_TIME.elapsed().as_millis(),
i
);
(10 * i..10 * (i + 1)).collect()
}
The current output is:
error[E0599]: the method `fuse` exists for struct `signal_hook_tokio::SignalsInfo`, but its trait bounds were not satisfied
--> regatta/examples/01-pages-hello-ok-int-c.rs:15:31
|
15 | let mut signals = signals.fuse();
| ^^^^ method cannot be called on `signal_hook_tokio::SignalsInfo` due to unsatisfied trait bounds
|
...
|
92 | pub struct SignalsInfo<E: Exfiltrator = SignalOnly>(OwningSignalIterator<UnixStream, E>);
| ----------------------------------------------------------------------------------------- doesn't satisfy `signal_hook_tokio::SignalsInfo: Iterator`
|
= note: the following trait bounds were not satisfied:
`signal_hook_tokio::SignalsInfo: Iterator`
which is required by `&mut signal_hook_tokio::SignalsInfo: Iterator`
For more information about this error, try `rustc --explain E0599`.
Ideally the output should be as shown in this comment in issue #36513 (via PR #69255)and this comment (Feb 2020) in issue #40375 (which seems to have changed back to uninformative per this comment (Jun 2020))
Actually the output we should see is the same as in the comment below (a subtle variation of this code) where helpful and correct messages are produced:
...
= help: items from traits can only be used if the trait is in scope
= note: the following trait is implemented but not in scope; perhaps add a `use` for it:
`use futures::StreamExt;`
To fix, add use futures::stream::{StreamExt};
This issue has tripped, at least two (new) users.
A question to Discord #beginners about the likely root cause of this error wasn't responded to so its a subtle issue.