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::{
commands::{wrap_command, wrap_origin_accessors},
macros::{wrap_fields, wrap_functions},
mem::{heap_move_nonnull, heap_remove},
mem::heap_move_nonnull,
};
use servicepoint::{Bitmap, BitmapCommand, CompressionCode, Origin};
use std::ptr::NonNull;
@ -22,13 +22,13 @@ wrap_functions!(associate BitmapCommand;
///
/// Returns: a new [BitmapCommand] instance.
fn new(
bitmap: NonNull<Bitmap>,
origin_x: usize,
origin_y: usize,
compression: CompressionCode,
bitmap: move NonNull<Bitmap>,
origin_x: val usize,
origin_y: val usize,
compression: val CompressionCode,
) -> NonNull<BitmapCommand> {
heap_move_nonnull(BitmapCommand {
bitmap: unsafe { heap_remove(bitmap) },
bitmap,
origin: Origin::new(origin_x, origin_y),
compression,
})
@ -38,9 +38,7 @@ wrap_functions!(associate BitmapCommand;
/// leaving other fields as their default values.
///
/// Rust equivalent: `BitmapCommand::from(bitmap)`
fn from_bitmap(
bitmap: NonNull<Bitmap>,
) -> NonNull<BitmapCommand> {
heap_move_nonnull(unsafe { heap_remove(bitmap) }.into())
fn from_bitmap(bitmap: move NonNull<Bitmap>) -> NonNull<BitmapCommand> {
heap_move_nonnull(bitmap.into())
}
);

View file

@ -1,7 +1,7 @@
use crate::{
commands::wrap_command,
macros::{wrap_fields, wrap_functions},
mem::{heap_move_nonnull, heap_remove},
mem::heap_move_nonnull,
};
use servicepoint::{
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Offset,
@ -32,13 +32,13 @@ wrap_functions!(associate BitVecCommand;
///
/// The contained [`DisplayBitVec`] is always uncompressed.
fn new(
bitvec: NonNull<DisplayBitVec>,
offset: usize,
operation: BinaryOperation,
compression: CompressionCode,
bitvec: move NonNull<DisplayBitVec>,
offset: val usize,
operation: val BinaryOperation,
compression: val CompressionCode,
) -> NonNull<BitVecCommand> {
heap_move_nonnull(BitVecCommand {
bitvec: unsafe { heap_remove(bitvec) },
bitvec,
offset,
operation,
compression,

View file

@ -1,7 +1,7 @@
use crate::{
commands::{wrap_command, wrap_origin_accessors},
macros::{wrap_fields, wrap_functions},
mem::{heap_move_nonnull, heap_remove},
mem::heap_move_nonnull,
};
use servicepoint::{BrightnessGrid, BrightnessGridCommand, Origin};
use std::ptr::NonNull;
@ -22,22 +22,20 @@ wrap_functions!(associate BrightnessGridCommand;
///
/// Returns: a new [BrightnessGridCommand] instance.
fn new(
grid: NonNull<BrightnessGrid>,
origin_x: usize,
origin_y: usize,
grid: move NonNull<BrightnessGrid>,
origin_x: val usize,
origin_y: val usize
) -> NonNull<BrightnessGridCommand> {
heap_move_nonnull(BrightnessGridCommand {
grid: unsafe { heap_remove(grid) },
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: NonNull<BrightnessGrid>,
) -> NonNull<BrightnessGridCommand> {
heap_move_nonnull(unsafe { heap_remove(grid) }.into())
fn from_grid(grid: move NonNull<BrightnessGrid>) -> NonNull<BrightnessGridCommand> {
heap_move_nonnull(grid.into())
}
);

View file

@ -1,7 +1,7 @@
use crate::{
commands::{wrap_command, wrap_origin_accessors},
macros::{wrap_fields, wrap_functions},
mem::{heap_move_nonnull, heap_remove},
mem::heap_move_nonnull,
};
use servicepoint::{CharGrid, CharGridCommand, Origin};
use std::ptr::NonNull;
@ -22,22 +22,20 @@ wrap_functions!(associate CharGridCommand;
///
/// Returns: a new [CharGridCommand] instance.
fn new(
grid: NonNull<CharGrid>,
origin_x: usize,
origin_y: usize,
grid: move NonNull<CharGrid>,
origin_x: val usize,
origin_y: val usize,
) -> NonNull<CharGridCommand> {
heap_move_nonnull(CharGridCommand {
grid: unsafe { heap_remove(grid) },
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: NonNull<CharGrid>,
) -> NonNull<CharGridCommand> {
heap_move_nonnull(unsafe { heap_remove(grid) }.into())
fn from_grid(grid: move NonNull<CharGrid>) -> NonNull<CharGridCommand> {
heap_move_nonnull(grid.into())
}
);

View file

@ -1,7 +1,7 @@
use crate::{
commands::{wrap_command, wrap_origin_accessors},
macros::{wrap_fields, wrap_functions},
mem::{heap_move_nonnull, heap_remove},
mem::heap_move_nonnull,
};
use servicepoint::{Cp437Grid, Cp437GridCommand, Origin};
use std::ptr::NonNull;
@ -22,22 +22,20 @@ wrap_functions!(associate Cp437GridCommand;
///
/// The origin is relative to the top-left of the display.
fn new(
grid: NonNull<Cp437Grid>,
origin_x: usize,
origin_y: usize,
grid: move NonNull<Cp437Grid>,
origin_x: val usize,
origin_y: val usize,
) -> NonNull<Cp437GridCommand> {
heap_move_nonnull(Cp437GridCommand {
grid: unsafe { heap_remove(grid) },
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: NonNull<Cp437Grid>,
) -> NonNull<Cp437GridCommand> {
heap_move_nonnull(unsafe { heap_remove(grid) }.into())
fn from_grid(grid: move NonNull<Cp437Grid>) -> NonNull<Cp437GridCommand> {
heap_move_nonnull(grid.into())
}
);

View file

@ -178,10 +178,7 @@ wrap_functions!(associate GenericCommand;
/// The packet is dropped in the process.
///
/// Returns: pointer to new [GenericCommand] instance or NULL if parsing failed.
fn try_from_packet(
packet: NonNull<Packet>,
) -> NonNull<GenericCommand> {
let packet = unsafe { heap_remove(packet) };
fn try_from_packet(packet: move NonNull<Packet>) -> NonNull<GenericCommand> {
let result = servicepoint::TypedCommand::try_from(packet)
.map(|value| match value {
TypedCommand::Clear(clear) => GenericCommand {

View file

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

View file

@ -17,31 +17,22 @@ pub use generic_command::*;
macro_rules! wrap_origin_accessors {
( $object_type:ident ) => {
::paste::paste! {
$crate::macros::wrap_functions!(associate $object_type;
$crate::macros::wrap_methods!($object_type;
#[doc = " Reads the origin field of the [`" $object_type "`]."]
fn get_origin(
command: ::core::ptr::NonNull<$object_type>,
origin_x: ::core::ptr::NonNull<usize>,
origin_y: ::core::ptr::NonNull<usize>,
ref command,
origin_x: mut ::core::ptr::NonNull<usize>,
origin_y: mut ::core::ptr::NonNull<usize>
) {
unsafe {
let origin = &command.as_ref().origin;
*origin_x.as_ptr() = origin.x;
*origin_y.as_ptr() = origin.y;
}
}
let origin = command.origin;
*origin_x = origin.x;
*origin_y = origin.y;
};
#[doc = " Overwrites the origin field of the [`" $object_type "`]."]
fn set_origin(
command: ::core::ptr::NonNull<$object_type>,
origin_x: usize,
origin_y: usize,
) {
unsafe {
$crate::macros::nonnull_as_mut!(command).origin =
::servicepoint::Origin::new(origin_x, origin_y);
}
}
fn set_origin(mut command, origin_x: val usize, origin_y: val usize) {
command.origin = ::servicepoint::Origin::new(origin_x, origin_y);
};
);
}
};