diff --git a/src/commands/cc_only.rs b/src/commands/cc_only.rs new file mode 100644 index 0000000..634e7d0 --- /dev/null +++ b/src/commands/cc_only.rs @@ -0,0 +1,23 @@ +use std::sync::Arc; + +macro_rules! command_code_only_command { + ($command_struct:ident) => { + #[derive(uniffi::Object)] + pub struct $command_struct; + + #[uniffi::export] + impl $command_struct { + #[uniffi::constructor] + pub fn new() -> Arc { + const _: () = + assert!(size_of::() == 0); + Arc::new($command_struct) + } + } + }; +} + +command_code_only_command!(ClearCommand); +command_code_only_command!(HardResetCommand); +command_code_only_command!(BitmapLegacyCommand); +command_code_only_command!(FadeOutCommand); diff --git a/src/command.rs b/src/commands/command.rs similarity index 89% rename from src/command.rs rename to src/commands/command.rs index bc59001..9041b33 100644 --- a/src/command.rs +++ b/src/commands/command.rs @@ -27,7 +27,7 @@ impl Command { pub fn brightness(brightness: u8) -> Result, ServicePointError> { servicepoint::Brightness::try_from(brightness) .map_err(move |value| ServicePointError::InvalidBrightness { - value + value, }) .map(GlobalBrightnessCommand::from) .map(servicepoint::TypedCommand::Brightness) @@ -56,8 +56,10 @@ impl Command { let actual = servicepoint::BitmapCommand { origin, bitmap, - compression: servicepoint::CompressionCode::try_from(compression as u16) - .unwrap(), + compression: servicepoint::CompressionCode::try_from( + compression as u16, + ) + .unwrap(), }; Self::internal_new(actual.into()) } @@ -70,7 +72,7 @@ impl Command { ) -> Arc { let origin = Origin::new(offset_x as usize, offset_y as usize); let grid = grid.actual.read().unwrap().clone(); - let actual = BrightnessGridCommand {origin, grid}; + let actual = BrightnessGridCommand { origin, grid }; Self::internal_new(actual.into()) } @@ -85,14 +87,18 @@ impl Command { let actual = BitVecCommand { offset: offset as usize, bitvec, - compression: servicepoint::CompressionCode::try_from(compression as u16) + compression: servicepoint::CompressionCode::try_from( + compression as u16, + ) .unwrap(), operation: match operation { - BinaryOperation::Overwrite => servicepoint::BinaryOperation::Overwrite, + BinaryOperation::Overwrite => { + servicepoint::BinaryOperation::Overwrite + } BinaryOperation::And => servicepoint::BinaryOperation::And, BinaryOperation::Or => servicepoint::BinaryOperation::Or, BinaryOperation::Xor => servicepoint::BinaryOperation::Xor, - } + }, }; Self::internal_new(actual.into()) } @@ -105,7 +111,7 @@ impl Command { ) -> Arc { let origin = Origin::new(offset_x as usize, offset_y as usize); let grid = grid.actual.read().unwrap().clone(); - let actual = Cp437GridCommand {origin, grid}; + let actual = Cp437GridCommand { origin, grid }; Self::internal_new(actual.into()) } @@ -117,7 +123,7 @@ impl Command { ) -> Arc { let origin = Origin::new(offset_x as usize, offset_y as usize); let grid = grid.actual.read().unwrap().clone(); - let actual = CharGridCommand {origin, grid}; + let actual = CharGridCommand { origin, grid }; Self::internal_new(actual.into()) } diff --git a/src/commands/mod.rs b/src/commands/mod.rs new file mode 100644 index 0000000..4be7e73 --- /dev/null +++ b/src/commands/mod.rs @@ -0,0 +1,3 @@ +pub mod command; + +pub mod cc_only; diff --git a/src/connection.rs b/src/connection.rs index 32c9b8a..1e6a63b 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -1,12 +1,6 @@ -use std::{ - net::UdpSocket, - sync::Arc -}; +use crate::{commands::command::Command, errors::ServicePointError}; use servicepoint::UdpSocketExt; -use crate::{ - command::Command, - errors::ServicePointError -}; +use std::{net::UdpSocket, sync::Arc}; #[derive(uniffi::Object)] pub struct Connection { @@ -25,10 +19,10 @@ impl Connection { } pub fn send(&self, command: Arc) -> Result<(), ServicePointError> { - self.actual.send_command(command.actual.read().unwrap().clone()).ok_or_else(|| { - ServicePointError::IoError { + self.actual + .send_command(command.actual.read().unwrap().clone()) + .ok_or_else(|| ServicePointError::IoError { error: "send failed".to_string(), - } - }) + }) } } diff --git a/src/lib.rs b/src/lib.rs index f491dbe..c7addef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ uniffi::setup_scaffolding!(); mod brightness; -mod command; mod commands; mod compression_code; mod connection;