formatting changes, mostly resulting from the shorter name

This commit is contained in:
Vinzenz Schroeter 2024-10-15 21:33:32 +02:00
parent 78a4d4dbcf
commit a08d439366
9 changed files with 75 additions and 70 deletions

View file

@ -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()
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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;