From e1f009ee6f7a145fb6c324b08db5767ea50d0fe0 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Sun, 23 Jun 2024 10:41:46 +0200 Subject: [PATCH] examples: error message on connection failure --- crates/servicepoint/examples/announce.rs | 8 +++++--- crates/servicepoint/examples/brightness_tester.rs | 3 ++- crates/servicepoint/examples/game_of_life.rs | 3 ++- crates/servicepoint/examples/moving_line.rs | 3 ++- crates/servicepoint/examples/random_brightness.rs | 3 ++- crates/servicepoint/examples/wiping_clear.rs | 5 +++-- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/crates/servicepoint/examples/announce.rs b/crates/servicepoint/examples/announce.rs index b165135..fd6609e 100644 --- a/crates/servicepoint/examples/announce.rs +++ b/crates/servicepoint/examples/announce.rs @@ -22,9 +22,11 @@ fn main() { cli.text.push("Hello, CCCB!".to_string()); } - let connection = Connection::open(&cli.destination).unwrap(); + let connection = Connection::open(&cli.destination) + .expect("could not connect to display"); + if cli.clear { - connection.send(Command::Clear).unwrap(); + connection.send(Command::Clear).expect("sending clear failed"); } let max_width = cli.text.iter().map(|t| t.len()).max().unwrap(); @@ -41,5 +43,5 @@ fn main() { connection .send(Command::Cp437Data(Origin(0, 0), chars)) - .unwrap(); + .expect("sending text failed"); } diff --git a/crates/servicepoint/examples/brightness_tester.rs b/crates/servicepoint/examples/brightness_tester.rs index b1b1ac3..798e94f 100644 --- a/crates/servicepoint/examples/brightness_tester.rs +++ b/crates/servicepoint/examples/brightness_tester.rs @@ -13,7 +13,8 @@ struct Cli { fn main() { let cli = Cli::parse(); - let connection = Connection::open(cli.destination).unwrap(); + let connection = Connection::open(cli.destination) + .expect("could not connect to display"); let mut pixels = PixelGrid::max_sized(); pixels.fill(true); diff --git a/crates/servicepoint/examples/game_of_life.rs b/crates/servicepoint/examples/game_of_life.rs index 9fff62e..47f1139 100644 --- a/crates/servicepoint/examples/game_of_life.rs +++ b/crates/servicepoint/examples/game_of_life.rs @@ -18,7 +18,8 @@ struct Cli { fn main() { let cli = Cli::parse(); - let connection = Connection::open(&cli.destination).unwrap(); + let connection = Connection::open(&cli.destination) + .expect("could not connect to display"); let mut field = make_random_field(cli.probability); loop { diff --git a/crates/servicepoint/examples/moving_line.rs b/crates/servicepoint/examples/moving_line.rs index f0353be..d2b4455 100644 --- a/crates/servicepoint/examples/moving_line.rs +++ b/crates/servicepoint/examples/moving_line.rs @@ -13,7 +13,8 @@ struct Cli { } fn main() { - let connection = Connection::open(Cli::parse().destination).unwrap(); + let connection = Connection::open(Cli::parse().destination) + .expect("could not connect to display"); let mut pixels = PixelGrid::max_sized(); for x_offset in 0..usize::MAX { diff --git a/crates/servicepoint/examples/random_brightness.rs b/crates/servicepoint/examples/random_brightness.rs index d9ea583..ad3dfae 100644 --- a/crates/servicepoint/examples/random_brightness.rs +++ b/crates/servicepoint/examples/random_brightness.rs @@ -22,7 +22,8 @@ struct Cli { fn main() { let cli = Cli::parse(); - let connection = Connection::open(cli.destination).unwrap(); + let connection = Connection::open(cli.destination) + .expect("could not connect to display"); let wait_duration = Duration::from_millis(cli.wait_ms); // put all pixels in on state diff --git a/crates/servicepoint/examples/wiping_clear.rs b/crates/servicepoint/examples/wiping_clear.rs index fdf84e3..03e8215 100644 --- a/crates/servicepoint/examples/wiping_clear.rs +++ b/crates/servicepoint/examples/wiping_clear.rs @@ -22,7 +22,8 @@ fn main() { Duration::from_millis(cli.time / PIXEL_WIDTH as u64), ); - let connection = Connection::open(cli.destination).unwrap(); + let connection = Connection::open(cli.destination) + .expect("could not connect to display"); let mut enabled_pixels = PixelGrid::new(PIXEL_WIDTH, PIXEL_HEIGHT); enabled_pixels.fill(true); @@ -38,7 +39,7 @@ fn main() { connection .send(Command::BitmapLinearAnd(0, bit_vec, CompressionCode::Lzma)) - .unwrap(); + .expect("could not send command to display"); thread::sleep(sleep_duration); } }