add parameter modifiers

This commit is contained in:
Vinzenz Schroeter 2025-06-23 23:28:30 +02:00
parent 664625402f
commit e8f11c08ea
17 changed files with 214 additions and 230 deletions

View file

@ -1,7 +1,7 @@
use crate::{
containers::{wrap_grid, ByteSlice},
macros::{derive_clone, derive_free, wrap_functions, wrap_methods},
mem::{heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove},
macros::{wrap_functions, wrap_methods},
mem::{heap_move_nonnull, heap_move_ok, heap_move_some},
};
use servicepoint::{
Bitmap, BitmapCommand, CompressionCode, DataRef, DisplayBitVec, Grid,
@ -35,7 +35,7 @@ wrap_functions!(associate Bitmap;
/// sp_bitmap_set(grid, 0, 0, false);
/// sp_bitmap_free(grid);
/// ```
fn new(width: usize, height: usize) -> *mut Bitmap {
fn new(width: val usize, height: val usize) -> *mut Bitmap {
heap_move_some(Bitmap::new(width, height))
}
@ -55,9 +55,9 @@ wrap_functions!(associate Bitmap;
///
/// returns: [Bitmap] that contains a copy of the provided data, or NULL in case of an error.
fn load(
width: usize,
height: usize,
data: ByteSlice,
width: val usize,
height: val usize,
data: val ByteSlice,
) -> *mut Bitmap {
let data = unsafe { data.as_slice() };
heap_move_ok(Bitmap::load(width, height, data))
@ -69,10 +69,9 @@ wrap_functions!(associate Bitmap;
///
/// Returns NULL in case of error.
fn from_bitvec(
width: usize,
bitvec: NonNull<DisplayBitVec>,
width: val usize,
bitvec: move NonNull<DisplayBitVec>,
) -> *mut Bitmap {
let bitvec = unsafe { heap_remove(bitvec) };
heap_move_ok(Bitmap::from_bitvec(width, bitvec))
}
);
@ -88,7 +87,7 @@ wrap_methods!(Bitmap;
/// The provided [Bitmap] gets consumed.
///
/// Returns NULL in case of an error.
fn try_into_packet(move bitmap, x: usize, y: usize, compression: CompressionCode) -> *mut Packet {
fn try_into_packet(move bitmap, x: val usize, y: val usize, compression: val CompressionCode) -> *mut Packet {
heap_move_ok(Packet::try_from(BitmapCommand {
bitmap,
origin: Origin::new(x, y),

View file

@ -1,6 +1,6 @@
use crate::{
containers::{wrap_container, ByteSlice},
macros::{derive_clone, derive_free, wrap_functions, wrap_methods},
macros::{wrap_functions, wrap_methods},
mem::{heap_move_nonnull, heap_move_ok},
};
use servicepoint::{
@ -23,14 +23,14 @@ wrap_functions!(associate DisplayBitVec;
/// # Panics
///
/// - when `size` is not divisible by 8.
fn new(size: usize) -> NonNull<DisplayBitVec> {
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.
///
/// returns: [DisplayBitVec] instance containing data.
fn load(data: ByteSlice) -> NonNull<DisplayBitVec> {
fn load(data: val ByteSlice) -> NonNull<DisplayBitVec> {
let data = unsafe { data.as_slice() };
heap_move_nonnull(DisplayBitVec::from_slice(data))
}
@ -45,9 +45,9 @@ wrap_methods!(DisplayBitVec;
/// Returns NULL in case of an error.
fn try_into_packet(
move bitvec,
offset: usize,
operation: BinaryOperation,
compression: CompressionCode
offset: val usize,
operation: val BinaryOperation,
compression: val CompressionCode
) -> *mut Packet {
heap_move_ok(Packet::try_from(BitVecCommand {
bitvec,
@ -69,7 +69,7 @@ wrap_methods!(DisplayBitVec;
/// # Panics
///
/// - when accessing `index` out of bounds
fn get(ref instance, index: usize) -> bool {
fn get(ref instance, index: val usize) -> bool {
instance.get(index).map(|x| *x).unwrap_or(false)
};
@ -83,14 +83,14 @@ wrap_methods!(DisplayBitVec;
/// # Panics
///
/// - when accessing `index` out of bounds
fn set(mut instance, index: usize, value: bool);
fn set(mut instance, index: val usize, value: val bool);
/// Sets the value of all bits.
///
/// # Arguments
///
/// - `value`: the value to set all bits to
fn fill(mut instance, value: bool);
fn fill(mut instance, value: val bool);
/// Gets the length in bits.
fn len(ref instance) -> usize;

View file

@ -1,6 +1,6 @@
use crate::{
containers::{wrap_grid, ByteSlice},
macros::{derive_clone, derive_free, wrap_functions, wrap_methods},
macros::{wrap_functions, wrap_methods},
mem::{heap_move_nonnull, heap_move_ok, heap_move_some},
};
use servicepoint::{
@ -30,10 +30,7 @@ wrap_functions!(associate BrightnessGrid;
/// TypedCommand *command = sp_command_char_brightness(grid);
/// sp_udp_free(connection);
/// ```
fn new(
width: usize,
height: usize,
) -> NonNull<BrightnessGrid> {
fn new(width: val usize, height: val usize) -> NonNull<BrightnessGrid> {
heap_move_nonnull(BrightnessGrid::new(width, height))
}
@ -43,9 +40,9 @@ wrap_functions!(associate BrightnessGrid;
///
/// returns: new [BrightnessGrid] instance, or NULL in case of an error.
fn load(
width: usize,
height: usize,
data: ByteSlice,
width: val usize,
height: val usize,
data: val ByteSlice,
) -> *mut BrightnessGrid {
let data = unsafe { data.as_slice() };
heap_move_some(
@ -62,7 +59,7 @@ wrap_methods!(BrightnessGrid;
/// The provided [BrightnessGrid] gets consumed.
///
/// Returns NULL in case of an error.
fn try_into_packet(move grid, x: usize, y: usize) -> *mut Packet {
fn try_into_packet(move grid, x: val usize, y: val usize) -> *mut Packet {
heap_move_ok(Packet::try_from(BrightnessGridCommand {
grid,
origin: Origin::new(x, y),

View file

@ -1,6 +1,6 @@
use crate::{
containers::{derive_get_width_height, wrap_container, ByteSlice},
macros::{derive_clone, derive_free, wrap_functions, wrap_methods},
macros::{wrap_functions, wrap_methods},
mem::{heap_move_nonnull, heap_move_ok},
};
use servicepoint::{CharGrid, CharGridCommand, Grid, Origin, Packet};
@ -23,14 +23,14 @@ wrap_functions!(associate CharGrid;
/// sp_char_grid_set(grid, 0, 0, '!');
/// sp_char_grid_free(grid);
/// ```
fn new(width: usize, height: usize) -> NonNull<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.
///
/// returns: new CharGrid or NULL in case of an error
fn load(width: usize, height: usize, data: ByteSlice) -> *mut 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()))
}
@ -49,7 +49,7 @@ wrap_methods!(CharGrid;
/// # Panics
///
/// - when accessing `x` or `y` out of bounds
fn get(ref instance, x: usize, y: usize) -> u32 {
fn get(ref instance, x: val usize, y: val usize) -> u32 {
instance.get(x, y) as u32
};
@ -66,7 +66,7 @@ wrap_methods!(CharGrid;
///
/// - when accessing `x` or `y` out of bounds
/// - when providing values that cannot be converted to Rust's `char`.
fn set(mut instance, x: usize, y: usize, value: u32) {
fn set(mut instance, x: val usize, y: val usize, value: val u32) {
instance.set(x, y, char::from_u32(value).unwrap())
};
@ -76,7 +76,7 @@ wrap_methods!(CharGrid;
///
/// - `value`: the value to set all cells to
/// - when providing values that cannot be converted to Rust's `char`.
fn fill(mut instance, value: u32) {
fn fill(mut instance, value: val u32) {
instance.fill(char::from_u32(value).unwrap())
};
@ -85,7 +85,7 @@ wrap_methods!(CharGrid;
/// The provided [CharGrid] gets consumed.
///
/// Returns NULL in case of an error.
fn try_into_packet(move grid, x: usize, y: usize) -> *mut Packet {
fn try_into_packet(move grid, x: val usize, y: val usize) -> *mut Packet {
heap_move_ok(Packet::try_from(CharGridCommand {
grid,
origin: Origin::new(x, y),

View file

@ -1,6 +1,6 @@
use crate::{
containers::{wrap_grid, ByteSlice},
macros::{derive_clone, derive_free, wrap_functions, wrap_methods},
macros::{wrap_functions, wrap_methods},
mem::{heap_move_nonnull, heap_move_ok, heap_move_some},
};
use servicepoint::{
@ -14,12 +14,12 @@ wrap_functions!(associate Cp437Grid;
/// Creates a new [Cp437Grid] with the specified dimensions.
///
/// returns: [Cp437Grid] initialized to 0.
fn new(width: usize, height: usize) -> NonNull<Cp437Grid> {
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: usize, height: usize, data: ByteSlice) -> *mut Cp437Grid {
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))
}
@ -31,7 +31,7 @@ wrap_methods!(Cp437Grid;
/// The provided [Cp437Grid] gets consumed.
///
/// Returns NULL in case of an error.
fn try_into_packet(move grid, x: usize, y: usize) -> *mut Packet {
fn try_into_packet(move grid, x: val usize, y: val usize) -> *mut Packet {
heap_move_ok(Packet::try_from(Cp437GridCommand {
grid,
origin: Origin::new(x, y),

View file

@ -14,8 +14,8 @@ pub use cp437_grid::*;
macro_rules! wrap_container {
($object_type:ident) => {
derive_clone!($object_type);
derive_free!($object_type);
$crate::macros::derive_clone!($object_type);
$crate::macros::derive_free!($object_type);
};
}
@ -45,7 +45,7 @@ macro_rules! wrap_grid {
/// # Panics
///
/// - when accessing `x` or `y` out of bounds
fn get(ref instance, x: usize, y: usize) -> $value_type;
fn get(ref instance, x: val usize, y: val usize) -> $value_type;
/// Sets the value of the specified position.
///
@ -57,14 +57,14 @@ macro_rules! wrap_grid {
/// # Panics
///
/// - when accessing `x` or `y` out of bounds
fn set(mut instance, x: usize, y: usize, value: $value_type);
fn set(mut instance, x: val usize, y: val usize, value: val $value_type);
/// Sets the state of all cells in the grid.
///
/// # Arguments
///
/// - `value`: the value to set all cells to
fn fill(mut instance, value: $value_type);
fn fill(mut instance, value: val $value_type);
}
};
}