cleanups, add semicolon everywhere

This commit is contained in:
Vinzenz Schroeter 2025-06-26 17:29:03 +02:00
parent e8f11c08ea
commit 0968605d0b
19 changed files with 192 additions and 87 deletions

View file

@ -32,7 +32,7 @@ wrap_functions!(associate BitmapCommand;
origin: Origin::new(origin_x, origin_y),
compression,
})
}
};
/// Move the provided [Bitmap] into a new [BitmapCommand],
/// leaving other fields as their default values.
@ -40,5 +40,5 @@ wrap_functions!(associate BitmapCommand;
/// Rust equivalent: `BitmapCommand::from(bitmap)`
fn from_bitmap(bitmap: move NonNull<Bitmap>) -> NonNull<BitmapCommand> {
heap_move_nonnull(bitmap.into())
}
};
);

View file

@ -18,7 +18,6 @@ wrap_fields!(BitVecCommand;
);
wrap_functions!(associate BitVecCommand;
/// Set pixel data starting at the pixel offset on screen.
///
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning
@ -43,6 +42,5 @@ wrap_functions!(associate BitVecCommand;
operation,
compression,
})
}
};
);

View file

@ -15,7 +15,6 @@ wrap_fields!(BrightnessGridCommand;
wrap_origin_accessors!(BrightnessGridCommand);
wrap_functions!(associate BrightnessGridCommand;
/// Set the brightness of individual tiles in a rectangular area of the display.
///
/// The passed [BrightnessGrid] gets consumed.
@ -30,12 +29,11 @@ wrap_functions!(associate BrightnessGridCommand;
grid,
origin: Origin::new(origin_x, origin_y),
})
}
};
/// Moves the provided [BrightnessGrid] into a new [BrightnessGridCommand],
/// leaving other fields as their default values.
fn from_grid(grid: move NonNull<BrightnessGrid>) -> NonNull<BrightnessGridCommand> {
heap_move_nonnull(grid.into())
}
};
);

View file

@ -14,7 +14,7 @@ macro_rules! wrap_cc_only {
#[doc = " Returns: a new [`" [< $command Command >] "`] instance."]
fn new() -> ::core::ptr::NonNull<[< $command Command >]> {
heap_move_nonnull([< $command Command >])
}
};
);
}
};

View file

@ -15,7 +15,6 @@ wrap_fields!(CharGridCommand;
wrap_origin_accessors!(CharGridCommand);
wrap_functions!(associate CharGridCommand;
/// Show UTF-8 encoded text on the screen.
///
/// The passed [CharGrid] gets consumed.
@ -30,12 +29,11 @@ wrap_functions!(associate CharGridCommand;
grid,
origin: Origin::new(origin_x, origin_y),
})
}
};
/// Moves the provided [CharGrid] into a new [CharGridCommand],
/// leaving other fields as their default values.
fn from_grid(grid: move NonNull<CharGrid>) -> NonNull<CharGridCommand> {
heap_move_nonnull(grid.into())
}
};
);

View file

@ -15,7 +15,6 @@ wrap_fields!(Cp437GridCommand;
wrap_origin_accessors!(Cp437GridCommand);
wrap_functions!(associate Cp437GridCommand;
/// Show text on the screen.
///
/// The text is sent in the form of a 2D grid of [CP-437] encoded characters.
@ -30,12 +29,11 @@ wrap_functions!(associate Cp437GridCommand;
grid,
origin: Origin::new(origin_x, origin_y),
})
}
};
/// Moves the provided [Cp437Grid] into a new [Cp437GridCommand],
/// leaving other fields as their default values.
fn from_grid(grid: move NonNull<Cp437Grid>) -> NonNull<Cp437GridCommand> {
heap_move_nonnull(grid.into())
}
};
);

View file

@ -248,7 +248,7 @@ wrap_functions!(associate GenericCommand;
data: CommandUnion { null: null_mut() },
});
heap_move_nonnull(result)
}
};
);
wrap_methods! { GenericCommand;

View file

@ -7,14 +7,12 @@ use servicepoint::{Brightness, GlobalBrightnessCommand};
use std::ptr::NonNull;
wrap_functions!(associate GlobalBrightnessCommand;
/// Set the brightness of all tiles to the same value.
///
/// Returns: a new [GlobalBrightnessCommand] instance.
fn new(brightness: val Brightness) -> NonNull<GlobalBrightnessCommand> {
heap_move_nonnull(GlobalBrightnessCommand::from(brightness))
}
};
);
wrap_command!(GlobalBrightness);

View file

@ -64,7 +64,7 @@ macro_rules! derive_command_into_packet {
/// Returns: NULL or a [Packet] containing the command.
fn try_into_packet(move instance) -> *mut ::servicepoint::Packet {
$crate::mem::heap_move_ok(instance.try_into())
}
};
);
}
}

View file

@ -37,14 +37,14 @@ wrap_functions!(associate Bitmap;
/// ```
fn new(width: val usize, height: val usize) -> *mut Bitmap {
heap_move_some(Bitmap::new(width, height))
}
};
/// Creates a new [Bitmap] with a size matching the screen.
///
/// returns: [Bitmap] initialized to all pixels off.
fn new_max_sized() -> NonNull<Bitmap> {
heap_move_nonnull(Bitmap::max_sized())
}
};
/// Loads a [Bitmap] with the specified dimensions from the provided data.
///
@ -61,7 +61,7 @@ wrap_functions!(associate Bitmap;
) -> *mut Bitmap {
let data = unsafe { data.as_slice() };
heap_move_ok(Bitmap::load(width, height, data))
}
};
/// Tries to convert the BitVec to a Bitmap.
///
@ -73,7 +73,7 @@ wrap_functions!(associate Bitmap;
bitvec: move NonNull<DisplayBitVec>,
) -> *mut Bitmap {
heap_move_ok(Bitmap::from_bitvec(width, bitvec))
}
};
);
wrap_methods!(Bitmap;

View file

@ -11,7 +11,6 @@ use std::ptr::NonNull;
wrap_container!(DisplayBitVec);
wrap_functions!(associate DisplayBitVec;
/// Creates a new [DisplayBitVec] instance.
///
/// # Arguments
@ -25,7 +24,7 @@ wrap_functions!(associate DisplayBitVec;
/// - when `size` is not divisible by 8.
fn new(size: val usize) -> NonNull<DisplayBitVec> {
heap_move_nonnull(DisplayBitVec::repeat(false, size))
}
};
/// Interpret the data as a series of bits and load then into a new [DisplayBitVec] instance.
///
@ -33,8 +32,7 @@ wrap_functions!(associate DisplayBitVec;
fn load(data: val ByteSlice) -> NonNull<DisplayBitVec> {
let data = unsafe { data.as_slice() };
heap_move_nonnull(DisplayBitVec::from_slice(data))
}
};
);
wrap_methods!(DisplayBitVec;

View file

@ -32,7 +32,7 @@ wrap_functions!(associate BrightnessGrid;
/// ```
fn new(width: val usize, height: val usize) -> NonNull<BrightnessGrid> {
heap_move_nonnull(BrightnessGrid::new(width, height))
}
};
/// Loads a [BrightnessGrid] with the specified dimensions from the provided data.
///
@ -49,7 +49,7 @@ wrap_functions!(associate BrightnessGrid;
ByteGrid::load(width, height, data)
.map(move |grid| grid.map(Brightness::saturating_from)),
)
}
};
);

View file

@ -10,7 +10,6 @@ wrap_container!(CharGrid);
derive_get_width_height!(CharGrid);
wrap_functions!(associate CharGrid;
/// Creates a new [CharGrid] with the specified dimensions.
///
/// returns: [CharGrid] initialized to 0.
@ -25,7 +24,7 @@ wrap_functions!(associate CharGrid;
/// ```
fn new(width: val usize, height: val usize) -> NonNull<CharGrid> {
heap_move_nonnull(CharGrid::new(width, height))
}
};
/// Loads a [CharGrid] with the specified dimensions from the provided data.
///
@ -33,9 +32,7 @@ wrap_functions!(associate CharGrid;
fn load(width: val usize, height: val usize, data: val ByteSlice) -> *mut CharGrid {
let data = unsafe { data.as_slice() };
heap_move_ok(CharGrid::load_utf8(width, height, data.to_vec()))
}
};
);
wrap_methods!(CharGrid;

View file

@ -16,13 +16,13 @@ wrap_functions!(associate Cp437Grid;
/// returns: [Cp437Grid] initialized to 0.
fn new(width: val usize, height: val usize) -> NonNull<Cp437Grid> {
heap_move_nonnull(Cp437Grid::new(width, height))
}
};
/// Loads a [Cp437Grid] with the specified dimensions from the provided data.
fn load(width: val usize, height: val usize, data: val ByteSlice) -> *mut Cp437Grid {
let data = unsafe { data.as_slice() };
heap_move_some(Cp437Grid::load(width, height, data))
}
};
);
wrap_methods!(Cp437Grid;

View file

@ -48,6 +48,6 @@ mod feature_env_logger {
/// `RUST_LOG` environment variable. See [env_logger](https://docs.rs/env_logger/latest/env_logger/).
fn init() {
env_logger::init();
}
};
);
}

View file

@ -1,48 +1,36 @@
macro_rules! derive_free {
($typ:ident) => {
::paste::paste! {
$crate::macros::wrap_functions!([< $typ:lower >];
$crate::macros::wrap_method!($typ;
#[doc = "Deallocates a [`" $typ "`] instance."]
#[allow(dropping_copy_types)]
fn free(instance: move ::core::ptr::NonNull<$typ>) {
fn free(move instance) {
::std::mem::drop(instance)
}
};
);
}
};
}
macro_rules! derive_clone {
($typ:ident) => {
($object_type:ident) => {
::paste::paste! {
$crate::macros::wrap_functions!([< $typ:lower >];
#[doc = "Clones a [`" $typ "`] instance."]
fn clone(instance: ref ::core::ptr::NonNull<$typ>) -> ::core::ptr::NonNull<$typ> {
$crate::macros::wrap_method!($object_type;
#[doc = "Clones a [`" $object_type "`] instance."]
fn clone(ref instance) -> ::core::ptr::NonNull<$object_type> {
$crate::mem::heap_move_nonnull(instance.clone())
}
};
);
}
};
}
macro_rules! nonnull_as_ref {
($ident:ident) => {
$ident.as_ref()
};
}
macro_rules! nonnull_as_mut {
($ident:ident) => {
(&mut *$ident.as_ptr())
};
}
macro_rules! wrap_method {
(
$object_type:ident;
$(#[$meta:meta])+
fn $function:ident($ref_or_mut:ident $instance:ident $(, $($param_name:ident: $param_modifier:ident $param_type:ty),*)?)
$(-> $return_type:ty)?
$(-> $return_type:ty)?;
) => {
::paste::paste!{
$crate::macros::wrap_method!(
@ -51,7 +39,7 @@ macro_rules! wrap_method {
fn $function($ref_or_mut $instance $(, $($param_name: $param_modifier $param_type),*)?)
$(-> $return_type)? {
$instance.$function($($($param_name),*)?)
}
};
);
}
};
@ -59,7 +47,7 @@ macro_rules! wrap_method {
$(#[$meta:meta])+
fn $function:ident($ref_or_mut:ident $instance:ident $(, $($param_name:ident: $param_modifier:ident $param_type:ty),*)?)
$(-> $return_type:ty)?
$impl:block
$impl:block;
) => {
paste::paste! {
$crate::macros::wrap_functions!([< $object_type:lower >];
@ -70,7 +58,7 @@ macro_rules! wrap_method {
$instance: $ref_or_mut ::core::ptr::NonNull<$object_type>
$(,$($param_name: $param_modifier $param_type),*)?
) $(-> $return_type)?
$impl
$impl;
);
}
};
@ -92,7 +80,7 @@ macro_rules! wrap_methods {
$(#[$meta])*
fn $function($ref_or_mut $instance $(, $($param_name: $param_modifier $param_type),*)?)
$(-> $return_type)?
$($impl)?
$($impl)?;
);
)+
}
@ -107,7 +95,7 @@ macro_rules! wrap_fields_accessor {
"` of the [`servicepoint::" $object_type "`]."]
fn [<get _ $prop_name>](ref instance) -> $prop_type {
return instance.$prop_name;
}
};
}
}
};
@ -121,7 +109,7 @@ macro_rules! wrap_fields_accessor {
/// - The returned pointer may not be used in a function that consumes the instance, e.g. to create a command.
fn [<get _ $prop_name _mut>](mut instance) -> ::core::ptr::NonNull<$prop_type> {
return ::core::ptr::NonNull::from(&mut instance.$prop_name);
}
};
}
}
};
@ -132,7 +120,7 @@ macro_rules! wrap_fields_accessor {
"` of the [`servicepoint::" $object_type "`]."]
fn [<set _ $prop_name>](mut instance, value: val $prop_type) {
instance.$prop_name = value;
}
};
}
}
};
@ -144,7 +132,7 @@ macro_rules! wrap_fields_accessor {
/// The provided value is moved into the instance, potentially invalidating previously taken references.
fn [<set _ $prop_name>](mut instance, value: move ::core::ptr::NonNull<$prop_type>) {
instance.$prop_name = value;
}
};
}
}
};
@ -176,10 +164,10 @@ macro_rules! apply_param_modifier {
$param_name
};
(mut, $param_name:ident) => {
unsafe { $crate::macros::nonnull_as_mut!($param_name) }
unsafe { (&mut *$param_name.as_ptr()) }
};
(ref, $param_name:ident) => {
unsafe { $crate::macros::nonnull_as_ref!($param_name) }
unsafe { $param_name.as_ref() }
};
}
@ -189,7 +177,7 @@ macro_rules! wrap_function {
$(#[$meta:meta])+
fn $function:ident($($param_name:ident: $param_modifier:ident $param_type:ty),*$(,)?)
$(-> $return_type:ty)?
$block:block
$block:block;
) => {
::paste::paste! {
$(#[$meta])*
@ -216,7 +204,7 @@ macro_rules! wrap_functions {
$(#[$meta:meta])+
fn $function:ident($($param_name:ident: $param_modifier:ident $param_type:ty),*$(,)?)
$(-> $return_type:ty)?
$block:block
$block:block;
)+
) => {
::paste::paste! {
@ -224,7 +212,7 @@ macro_rules! wrap_functions {
$crate::macros::wrap_function!($module;
$(#[$meta])+
fn $function($($param_name: $param_modifier $param_type),*) $(-> $return_type)?
$block
$block;
);
)+
}
@ -235,7 +223,7 @@ macro_rules! wrap_functions {
$(#[$meta:meta])+
fn $function:ident($($param_name:ident: $param_modifier:ident $param_type:ty),*$(,)?)
$(-> $return_type:ty)?
$block:block
$block:block;
)+
) => {
::paste::paste! {
@ -243,7 +231,7 @@ macro_rules! wrap_functions {
$(
$(#[$meta])+
fn $function($($param_name: $param_modifier $param_type),*) $(-> $return_type)?
$block
$block;
)+
}
}
@ -251,7 +239,7 @@ macro_rules! wrap_functions {
}
pub(crate) use {
apply_param_modifier, derive_clone, derive_free, nonnull_as_mut,
nonnull_as_ref, wrap_fields, wrap_fields_accessor, wrap_function,
apply_param_modifier, derive_clone, derive_free,
wrap_fields, wrap_fields_accessor, wrap_function,
wrap_functions, wrap_method, wrap_methods,
};

View file

@ -15,7 +15,7 @@ wrap_functions!(associate Packet;
fn try_load(data: val ByteSlice) -> *mut Packet {
let data = unsafe { data.as_slice() };
heap_move_ok(servicepoint::Packet::try_from(data))
}
};
/// Creates a raw [Packet] from parts.
///
@ -28,7 +28,7 @@ wrap_functions!(associate Packet;
};
heap_move_nonnull(Packet { header, payload })
}
};
);
derive_clone!(Packet);
@ -87,6 +87,5 @@ wrap_functions!(sp;
}
Err(_) => false,
}
}
};
);

View file

@ -29,9 +29,8 @@ wrap_functions!(associate UdpSocket;
let host = unsafe { CStr::from_ptr(host.as_ptr()) }
.to_str()
.expect("Bad encoding");
heap_move_ok(UdpSocket::bind_connect(host))
}
};
/// Creates a new instance of [UdpSocket].
///
@ -47,7 +46,7 @@ wrap_functions!(associate UdpSocket;
fn open_ipv4(ip1: val u8, ip2: val u8, ip3: val u8, ip4: val u8, port: val u16) -> *mut UdpSocket {
let addr = SocketAddrV4::new(Ipv4Addr::from([ip1, ip2, ip3, ip4]), port);
heap_move_ok(UdpSocket::bind_connect(addr))
}
};
);