From e9dc4b59d2084a41c7747ae1ae6bd49b099adbde Mon Sep 17 00:00:00 2001 From: Annika Hannig Date: Thu, 23 May 2024 20:56:46 +0200 Subject: [PATCH] only require into Packet for sendable data --- examples/announce/src/main.rs | 4 ++-- examples/game_of_life/src/main.rs | 1 - examples/moving_line/src/main.rs | 1 - examples/random_brightness/src/main.rs | 6 +++--- examples/wiping_clear/src/main.rs | 1 - servicepoint2/src/connection.rs | 9 ++++++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/announce/src/main.rs b/examples/announce/src/main.rs index 7d90b7e..1c9929d 100644 --- a/examples/announce/src/main.rs +++ b/examples/announce/src/main.rs @@ -21,7 +21,7 @@ fn main() { let connection = Connection::open(&cli.destination).unwrap(); if cli.clear { - connection.send(Command::Clear.into()).unwrap(); + connection.send(Command::Clear).unwrap(); } let max_width = cli.text.iter().map(|t| t.len()).max().unwrap(); @@ -37,6 +37,6 @@ fn main() { } connection - .send(Command::Cp437Data(Origin(0, 0), chars).into()) + .send(Command::Cp437Data(Origin(0, 0), chars)) .unwrap(); } diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 4f04464..04be3cd 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -28,7 +28,6 @@ fn main() { field.clone(), CompressionCode::Lzma, ) - .into(), ) .expect("could not send"); thread::sleep(FRAME_PACING); diff --git a/examples/moving_line/src/main.rs b/examples/moving_line/src/main.rs index 9800c3b..6ec9f1b 100644 --- a/examples/moving_line/src/main.rs +++ b/examples/moving_line/src/main.rs @@ -29,7 +29,6 @@ fn main() { pixels.clone(), CompressionCode::Lzma, ) - .into(), ) .unwrap(); thread::sleep(FRAME_PACING); diff --git a/examples/random_brightness/src/main.rs b/examples/random_brightness/src/main.rs index d1f65ce..aa0d1f6 100644 --- a/examples/random_brightness/src/main.rs +++ b/examples/random_brightness/src/main.rs @@ -30,12 +30,12 @@ fn main() { let command = BitmapLinearWin(Origin(0, 0), filled_grid, CompressionCode::Lzma); - connection.send(command.into()).expect("send failed"); + connection.send(command).expect("send failed"); } // set all pixels to the same random brightness let mut rng = rand::thread_rng(); - connection.send(Brightness(rng.gen()).into()).unwrap(); + connection.send(Brightness(rng.gen())).unwrap(); // continuously update random windows to new random brightness loop { @@ -56,7 +56,7 @@ fn main() { } connection - .send(CharBrightness(origin, luma).into()) + .send(CharBrightness(origin, luma)) .unwrap(); std::thread::sleep(wait_duration); } diff --git a/examples/wiping_clear/src/main.rs b/examples/wiping_clear/src/main.rs index 74d6258..08131b6 100644 --- a/examples/wiping_clear/src/main.rs +++ b/examples/wiping_clear/src/main.rs @@ -39,7 +39,6 @@ fn main() { connection .send( Command::BitmapLinearAnd(0, bit_vec, CompressionCode::Lzma) - .into(), ) .unwrap(); thread::sleep(sleep_duration); diff --git a/servicepoint2/src/connection.rs b/servicepoint2/src/connection.rs index 01443d5..559cdcb 100644 --- a/servicepoint2/src/connection.rs +++ b/servicepoint2/src/connection.rs @@ -10,6 +10,8 @@ pub struct Connection { socket: UdpSocket, } + + impl Connection { /// Open a new UDP socket and connect to the provided host. /// @@ -51,7 +53,7 @@ impl Connection { /// .expect("connection failed"); /// /// // turn off all pixels - /// connection.send(Command::Clear.into()) + /// connection.send(Command::Clear) /// .expect("send failed"); /// /// // turn on all pixels @@ -59,10 +61,11 @@ impl Connection { /// pixels.fill(true); /// /// // send pixels to display - /// connection.send(Command::BitmapLinearWin(servicepoint2::Origin(0, 0), pixels, CompressionCode::Uncompressed).into()) + /// connection.send(Command::BitmapLinearWin(servicepoint2::Origin(0, 0), pixels, CompressionCode::Uncompressed)) /// .expect("send failed"); /// ``` - pub fn send(&self, packet: Packet) -> Result<(), std::io::Error> { + pub fn send(&self, packet: impl Into) -> Result<(), std::io::Error> { + let packet = packet.into(); debug!("sending {packet:?}"); let data: Vec = packet.into(); self.socket.send(&data)?;