diff --git a/crates/servicepoint/examples/websocket.rs b/crates/servicepoint/examples/websocket.rs index b982633..a0c43c0 100644 --- a/crates/servicepoint/examples/websocket.rs +++ b/crates/servicepoint/examples/websocket.rs @@ -1,7 +1,7 @@ //! Example for how to use the WebSocket connection use servicepoint::{ - Command, CompressionCode, Connection, Grid, Origin, Bitmap, + Bitmap, Command, CompressionCode, Connection, Grid, Origin, }; fn main() { diff --git a/crates/servicepoint/src/bitmap.rs b/crates/servicepoint/src/bitmap.rs index 9eabf96..657e155 100644 --- a/crates/servicepoint/src/bitmap.rs +++ b/crates/servicepoint/src/bitmap.rs @@ -197,7 +197,7 @@ impl<'t> Iterator for IterRows<'t> { #[cfg(test)] mod tests { - use crate::{DataRef, Grid, Bitmap}; + use crate::{Bitmap, DataRef, Grid}; #[test] fn fill() { diff --git a/crates/servicepoint/src/command.rs b/crates/servicepoint/src/command.rs index 94a161a..51235fd 100644 --- a/crates/servicepoint/src/command.rs +++ b/crates/servicepoint/src/command.rs @@ -4,7 +4,7 @@ use crate::{ command_code::CommandCode, compression::into_decompressed, packet::{Header, Packet}, - Brightness, BrightnessGrid, CompressionCode, Cp437Grid, Origin, Bitmap, + Bitmap, Brightness, BrightnessGrid, CompressionCode, Cp437Grid, Origin, Pixels, PrimitiveGrid, SpBitVec, Tiles, TILE_SIZE, }; @@ -495,8 +495,8 @@ mod tests { command_code::CommandCode, origin::Pixels, packet::{Header, Packet}, - Brightness, BrightnessGrid, Command, CompressionCode, Origin, - Bitmap, PrimitiveGrid, + Bitmap, Brightness, BrightnessGrid, Command, CompressionCode, Origin, + PrimitiveGrid, }; fn round_trip(original: Command) { @@ -903,6 +903,7 @@ mod tests { Origin::new(1, 0) + Origin::new(3, 2) ); } + #[test] fn packet_into_char_brightness_invalid() { let grid = BrightnessGrid::new(2, 2); diff --git a/crates/servicepoint/src/lib.rs b/crates/servicepoint/src/lib.rs index 0d8e871..3848967 100644 --- a/crates/servicepoint/src/lib.rs +++ b/crates/servicepoint/src/lib.rs @@ -40,6 +40,7 @@ use std::time::Duration; pub use bitvec; use bitvec::prelude::{BitVec, Msb0}; +pub use crate::bitmap::Bitmap; pub use crate::brightness::{Brightness, BrightnessGrid}; pub use crate::command::{Command, Offset}; pub use crate::compression_code::CompressionCode; @@ -48,11 +49,11 @@ pub use crate::cp437::{CharGrid, Cp437Grid}; pub use crate::data_ref::DataRef; pub use crate::grid::Grid; pub use crate::origin::{Origin, Pixels, Tiles}; -pub use crate::bitmap::Bitmap; pub use crate::primitive_grid::PrimitiveGrid; type SpBitVec = BitVec; +mod bitmap; mod brightness; mod command; mod command_code; @@ -64,7 +65,6 @@ mod data_ref; mod grid; mod origin; pub mod packet; -mod bitmap; mod primitive_grid; /// size of a single tile in one dimension diff --git a/crates/servicepoint/src/packet.rs b/crates/servicepoint/src/packet.rs index 87fd8b6..2b8688d 100644 --- a/crates/servicepoint/src/packet.rs +++ b/crates/servicepoint/src/packet.rs @@ -27,8 +27,8 @@ use std::mem::size_of; use crate::compression::into_compressed; use crate::{ - command_code::CommandCode, Command, CompressionCode, Grid, Offset, Origin, - Bitmap, Pixels, Tiles, TILE_SIZE, + command_code::CommandCode, Bitmap, Command, CompressionCode, Grid, Offset, + Origin, Pixels, Tiles, TILE_SIZE, }; /// A raw header. diff --git a/crates/servicepoint_binding_c/src/bitmap.rs b/crates/servicepoint_binding_c/src/bitmap.rs index 22d9a57..0c4271c 100644 --- a/crates/servicepoint_binding_c/src/bitmap.rs +++ b/crates/servicepoint_binding_c/src/bitmap.rs @@ -210,10 +210,7 @@ pub unsafe extern "C" fn sp_bitmap_set( /// - `bitmap` points to a valid [SPBitmap] /// - `bitmap` is not written to or read from concurrently #[no_mangle] -pub unsafe extern "C" fn sp_bitmap_fill( - bitmap: *mut SPBitmap, - value: bool, -) { +pub unsafe extern "C" fn sp_bitmap_fill(bitmap: *mut SPBitmap, value: bool) { assert!(!bitmap.is_null()); (*bitmap).0.fill(value); } @@ -234,9 +231,7 @@ pub unsafe extern "C" fn sp_bitmap_fill( /// /// - `bitmap` points to a valid [SPBitmap] #[no_mangle] -pub unsafe extern "C" fn sp_bitmap_width( - bitmap: *const SPBitmap, -) -> usize { +pub unsafe extern "C" fn sp_bitmap_width(bitmap: *const SPBitmap) -> usize { assert!(!bitmap.is_null()); (*bitmap).0.width() } @@ -257,9 +252,7 @@ pub unsafe extern "C" fn sp_bitmap_width( /// /// - `bitmap` points to a valid [SPBitmap] #[no_mangle] -pub unsafe extern "C" fn sp_bitmap_height( - bitmap: *const SPBitmap, -) -> usize { +pub unsafe extern "C" fn sp_bitmap_height(bitmap: *const SPBitmap) -> usize { assert!(!bitmap.is_null()); (*bitmap).0.height() } diff --git a/crates/servicepoint_binding_c/src/command.rs b/crates/servicepoint_binding_c/src/command.rs index 4a64829..db86551 100644 --- a/crates/servicepoint_binding_c/src/command.rs +++ b/crates/servicepoint_binding_c/src/command.rs @@ -7,8 +7,8 @@ use std::ptr::null_mut; use servicepoint::{Brightness, Origin}; use crate::{ - SPBitVec, SPBrightnessGrid, SPCompressionCode, SPCp437Grid, SPPacket, - SPBitmap, + SPBitVec, SPBitmap, SPBrightnessGrid, SPCompressionCode, SPCp437Grid, + SPPacket, }; /// A low-level display command. @@ -107,7 +107,8 @@ pub unsafe extern "C" fn sp_command_clone( /// by explicitly calling `sp_command_free`. #[no_mangle] pub unsafe extern "C" fn sp_command_clear() -> *mut SPCommand { - let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::Clear))); + let result = + Box::into_raw(Box::new(SPCommand(servicepoint::Command::Clear))); assert!(!result.is_null()); result } @@ -126,7 +127,8 @@ pub unsafe extern "C" fn sp_command_clear() -> *mut SPCommand { /// by explicitly calling `sp_command_free`. #[no_mangle] pub unsafe extern "C" fn sp_command_hard_reset() -> *mut SPCommand { - let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::HardReset))); + let result = + Box::into_raw(Box::new(SPCommand(servicepoint::Command::HardReset))); assert!(!result.is_null()); result } @@ -143,7 +145,8 @@ pub unsafe extern "C" fn sp_command_hard_reset() -> *mut SPCommand { /// by explicitly calling `sp_command_free`. #[no_mangle] pub unsafe extern "C" fn sp_command_fade_out() -> *mut SPCommand { - let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::FadeOut))); + let result = + Box::into_raw(Box::new(SPCommand(servicepoint::Command::FadeOut))); assert!(!result.is_null()); result } @@ -168,9 +171,9 @@ pub unsafe extern "C" fn sp_command_brightness( ) -> *mut SPCommand { let brightness = Brightness::try_from(brightness).expect("invalid brightness"); - let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::Brightness( - brightness, - )))); + let result = Box::into_raw(Box::new(SPCommand( + servicepoint::Command::Brightness(brightness), + ))); assert!(!result.is_null()); result } @@ -201,10 +204,9 @@ pub unsafe extern "C" fn sp_command_char_brightness( ) -> *mut SPCommand { assert!(!grid.is_null()); let byte_grid = *Box::from_raw(grid); - let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::CharBrightness( - Origin::new(x, y), - byte_grid.0, - )))); + let result = Box::into_raw(Box::new(SPCommand( + servicepoint::Command::CharBrightness(Origin::new(x, y), byte_grid.0), + ))); assert!(!result.is_null()); result } @@ -242,11 +244,13 @@ pub unsafe extern "C" fn sp_command_bitmap_linear( ) -> *mut SPCommand { assert!(!bit_vec.is_null()); let bit_vec = *Box::from_raw(bit_vec); - let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::BitmapLinear( - offset, - bit_vec.into(), - compression.try_into().expect("invalid compression code"), - )))); + let result = Box::into_raw(Box::new(SPCommand( + servicepoint::Command::BitmapLinear( + offset, + bit_vec.into(), + compression.try_into().expect("invalid compression code"), + ), + ))); assert!(!result.is_null()); result } @@ -284,11 +288,13 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_and( ) -> *mut SPCommand { assert!(!bit_vec.is_null()); let bit_vec = *Box::from_raw(bit_vec); - let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::BitmapLinearAnd( - offset, - bit_vec.into(), - compression.try_into().expect("invalid compression code"), - )))); + let result = Box::into_raw(Box::new(SPCommand( + servicepoint::Command::BitmapLinearAnd( + offset, + bit_vec.into(), + compression.try_into().expect("invalid compression code"), + ), + ))); assert!(!result.is_null()); result } @@ -326,11 +332,13 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_or( ) -> *mut SPCommand { assert!(!bit_vec.is_null()); let bit_vec = *Box::from_raw(bit_vec); - let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::BitmapLinearOr( - offset, - bit_vec.into(), - compression.try_into().expect("invalid compression code"), - )))); + let result = Box::into_raw(Box::new(SPCommand( + servicepoint::Command::BitmapLinearOr( + offset, + bit_vec.into(), + compression.try_into().expect("invalid compression code"), + ), + ))); assert!(!result.is_null()); result } @@ -368,11 +376,13 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_xor( ) -> *mut SPCommand { assert!(!bit_vec.is_null()); let bit_vec = *Box::from_raw(bit_vec); - let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::BitmapLinearXor( - offset, - bit_vec.into(), - compression.try_into().expect("invalid compression code"), - )))); + let result = Box::into_raw(Box::new(SPCommand( + servicepoint::Command::BitmapLinearXor( + offset, + bit_vec.into(), + compression.try_into().expect("invalid compression code"), + ), + ))); assert!(!result.is_null()); result } @@ -403,10 +413,9 @@ pub unsafe extern "C" fn sp_command_cp437_data( ) -> *mut SPCommand { assert!(!grid.is_null()); let grid = *Box::from_raw(grid); - let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::Cp437Data( - Origin::new(x, y), - grid.0, - )))); + let result = Box::into_raw(Box::new(SPCommand( + servicepoint::Command::Cp437Data(Origin::new(x, y), grid.0), + ))); assert!(!result.is_null()); result } @@ -440,13 +449,15 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_win( ) -> *mut SPCommand { assert!(!bitmap.is_null()); let byte_grid = (*Box::from_raw(bitmap)).0; - let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::BitmapLinearWin( - Origin::new(x, y), - byte_grid, - compression_code - .try_into() - .expect("invalid compression code"), - )))); + let result = Box::into_raw(Box::new(SPCommand( + servicepoint::Command::BitmapLinearWin( + Origin::new(x, y), + byte_grid, + compression_code + .try_into() + .expect("invalid compression code"), + ), + ))); assert!(!result.is_null()); result } diff --git a/crates/servicepoint_binding_c/src/cp437_grid.rs b/crates/servicepoint_binding_c/src/cp437_grid.rs index 791c594..e458a1b 100644 --- a/crates/servicepoint_binding_c/src/cp437_grid.rs +++ b/crates/servicepoint_binding_c/src/cp437_grid.rs @@ -40,9 +40,9 @@ pub unsafe extern "C" fn sp_cp437_grid_new( width: usize, height: usize, ) -> *mut SPCp437Grid { - let result = Box::into_raw(Box::new(SPCp437Grid(servicepoint::Cp437Grid::new( - width, height, - )))); + let result = Box::into_raw(Box::new(SPCp437Grid( + servicepoint::Cp437Grid::new(width, height), + ))); assert!(!result.is_null()); result } @@ -73,9 +73,9 @@ pub unsafe extern "C" fn sp_cp437_grid_load( ) -> *mut SPCp437Grid { assert!(data.is_null()); let data = std::slice::from_raw_parts(data, data_length); - let result = Box::into_raw(Box::new(SPCp437Grid(servicepoint::Cp437Grid::load( - width, height, data, - )))); + let result = Box::into_raw(Box::new(SPCp437Grid( + servicepoint::Cp437Grid::load(width, height, data), + ))); assert!(!result.is_null()); result } diff --git a/crates/servicepoint_binding_c/src/lib.rs b/crates/servicepoint_binding_c/src/lib.rs index 7698252..2c9006d 100644 --- a/crates/servicepoint_binding_c/src/lib.rs +++ b/crates/servicepoint_binding_c/src/lib.rs @@ -26,6 +26,7 @@ //! ``` pub use crate::bit_vec::*; +pub use crate::bitmap::*; pub use crate::brightness_grid::*; pub use crate::byte_slice::*; pub use crate::command::*; @@ -33,9 +34,9 @@ pub use crate::connection::*; pub use crate::constants::*; pub use crate::cp437_grid::*; pub use crate::packet::*; -pub use crate::bitmap::*; mod bit_vec; +mod bitmap; mod brightness_grid; mod byte_slice; mod command; @@ -43,4 +44,3 @@ mod connection; mod constants; mod cp437_grid; mod packet; -mod bitmap;