Last active
July 20, 2025 17:47
-
-
Save webstrand/33e0c8b8de167fd389e036bae41ebe4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env -S cargo +nightly -Zscript | |
| ---cargo | |
| [dependencies] | |
| futures = "0.3.31" | |
| input-linux = { version = "0.7.1", features = ["codec", "tokio-util-0_7"] } | |
| tokio = { version = "1.46.1", features = ["full"] } | |
| tokio-util = { version = "0.7.15", features = ["full"] } | |
| --- | |
| use futures::StreamExt; | |
| use tokio_util::codec::FramedRead; | |
| #[tokio::main] | |
| async fn main() -> std::io::Result<()> { | |
| let input_file = tokio::fs::File::open("/dev/input/event2").await.unwrap(); | |
| let mut event_stream = FramedRead::new(input_file, input_linux::EventCodec::new()); | |
| println!("Press and hold any key to see bug"); | |
| let mut i = 0; | |
| loop { | |
| i += 1; | |
| match event_stream.next().await { | |
| Some(Ok(event)) => { | |
| // the unwrap must not be optimized away | |
| std::hint::black_box(event); | |
| // do something | |
| use std::io::Write; | |
| std::io::stdout().write(b".").unwrap(); | |
| std::io::stdout().flush().unwrap(); | |
| } | |
| Some(Err(e)) => { | |
| println!("\nERROR reading event: {}\nERROR kind: {}", e, e.kind()); | |
| break; | |
| } | |
| None => { | |
| println!("Stream ended"); | |
| break; | |
| } | |
| } | |
| } | |
| println!("Encountered {} events before bug", i); | |
| Ok(()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment