implement return modifiers

This commit is contained in:
Vinzenz Schroeter 2025-06-26 18:59:46 +02:00
parent 0968605d0b
commit 39c7c27c86
18 changed files with 144 additions and 146 deletions

View file

@ -1,7 +1,6 @@
use crate::{
commands::{wrap_command, wrap_origin_accessors},
macros::{wrap_fields, wrap_functions},
mem::heap_move_nonnull,
};
use servicepoint::{Bitmap, BitmapCommand, CompressionCode, Origin};
use std::ptr::NonNull;
@ -26,19 +25,19 @@ wrap_functions!(associate BitmapCommand;
origin_x: val usize,
origin_y: val usize,
compression: val CompressionCode,
) -> NonNull<BitmapCommand> {
heap_move_nonnull(BitmapCommand {
) -> move NonNull<BitmapCommand> {
BitmapCommand {
bitmap,
origin: Origin::new(origin_x, origin_y),
compression,
})
}
};
/// Move the provided [Bitmap] into a new [BitmapCommand],
/// leaving other fields as their default values.
///
/// Rust equivalent: `BitmapCommand::from(bitmap)`
fn from_bitmap(bitmap: move NonNull<Bitmap>) -> NonNull<BitmapCommand> {
heap_move_nonnull(bitmap.into())
fn from_bitmap(bitmap: move NonNull<Bitmap>) -> move NonNull<BitmapCommand> {
bitmap.into()
};
);

View file

@ -1,7 +1,6 @@
use crate::{
commands::wrap_command,
macros::{wrap_fields, wrap_functions},
mem::heap_move_nonnull,
};
use servicepoint::{
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Offset,
@ -35,12 +34,12 @@ wrap_functions!(associate BitVecCommand;
offset: val usize,
operation: val BinaryOperation,
compression: val CompressionCode,
) -> NonNull<BitVecCommand> {
heap_move_nonnull(BitVecCommand {
) -> move NonNull<BitVecCommand> {
BitVecCommand {
bitvec,
offset,
operation,
compression,
})
}
};
);

View file

@ -1,7 +1,6 @@
use crate::{
commands::{wrap_command, wrap_origin_accessors},
macros::{wrap_fields, wrap_functions},
mem::heap_move_nonnull,
};
use servicepoint::{BrightnessGrid, BrightnessGridCommand, Origin};
use std::ptr::NonNull;
@ -24,16 +23,16 @@ wrap_functions!(associate BrightnessGridCommand;
grid: move NonNull<BrightnessGrid>,
origin_x: val usize,
origin_y: val usize
) -> NonNull<BrightnessGridCommand> {
heap_move_nonnull(BrightnessGridCommand {
) -> move NonNull<BrightnessGridCommand> {
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())
fn from_grid(grid: move NonNull<BrightnessGrid>) -> move NonNull<BrightnessGridCommand> {
grid.into()
};
);

View file

@ -1,6 +1,4 @@
use crate::{
commands::wrap_command, macros::wrap_functions, mem::heap_move_nonnull,
};
use crate::{commands::wrap_command, macros::wrap_functions};
use servicepoint::{ClearCommand, FadeOutCommand, HardResetCommand};
macro_rules! wrap_cc_only {
@ -12,8 +10,8 @@ macro_rules! wrap_cc_only {
$(#[$meta])*
///
#[doc = " Returns: a new [`" [< $command Command >] "`] instance."]
fn new() -> ::core::ptr::NonNull<[< $command Command >]> {
heap_move_nonnull([< $command Command >])
fn new() -> move ::core::ptr::NonNull<[< $command Command >]> {
[< $command Command >]
};
);
}

View file

@ -1,7 +1,6 @@
use crate::{
commands::{wrap_command, wrap_origin_accessors},
macros::{wrap_fields, wrap_functions},
mem::heap_move_nonnull,
};
use servicepoint::{CharGrid, CharGridCommand, Origin};
use std::ptr::NonNull;
@ -24,16 +23,16 @@ wrap_functions!(associate CharGridCommand;
grid: move NonNull<CharGrid>,
origin_x: val usize,
origin_y: val usize,
) -> NonNull<CharGridCommand> {
heap_move_nonnull(CharGridCommand {
) -> move NonNull<CharGridCommand> {
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())
fn from_grid(grid: move NonNull<CharGrid>) -> move NonNull<CharGridCommand> {
grid.into()
};
);

View file

@ -1,7 +1,6 @@
use crate::{
commands::{wrap_command, wrap_origin_accessors},
macros::{wrap_fields, wrap_functions},
mem::heap_move_nonnull,
};
use servicepoint::{Cp437Grid, Cp437GridCommand, Origin};
use std::ptr::NonNull;
@ -24,16 +23,16 @@ wrap_functions!(associate Cp437GridCommand;
grid: move NonNull<Cp437Grid>,
origin_x: val usize,
origin_y: val usize,
) -> NonNull<Cp437GridCommand> {
heap_move_nonnull(Cp437GridCommand {
) -> move NonNull<Cp437GridCommand> {
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())
fn from_grid(grid: move NonNull<Cp437Grid>) -> move NonNull<Cp437GridCommand> {
grid.into()
};
);

View file

@ -178,8 +178,8 @@ 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: move NonNull<Packet>) -> NonNull<GenericCommand> {
let result = servicepoint::TypedCommand::try_from(packet)
fn try_from_packet(packet: move NonNull<Packet>) -> move NonNull<GenericCommand> {
servicepoint::TypedCommand::try_from(packet)
.map(|value| match value {
TypedCommand::Clear(clear) => GenericCommand {
tag: CommandTag::Clear,
@ -246,8 +246,7 @@ wrap_functions!(associate GenericCommand;
.unwrap_or_else(move |_| GenericCommand {
tag: CommandTag::Invalid,
data: CommandUnion { null: null_mut() },
});
heap_move_nonnull(result)
})
};
);
@ -256,7 +255,7 @@ wrap_methods! { GenericCommand;
/// The [GenericCommand] gets consumed.
///
/// Returns tag [CommandTag::Invalid] in case of an error.
fn try_into_packet(move command) -> *mut Packet {
fn try_into_packet(move command) -> val *mut Packet {
match command.tag {
CommandTag::Invalid => null_mut(),
CommandTag::Bitmap => {

View file

@ -1,7 +1,6 @@
use crate::{
commands::wrap_command,
macros::{wrap_fields, wrap_functions},
mem::heap_move_nonnull,
};
use servicepoint::{Brightness, GlobalBrightnessCommand};
use std::ptr::NonNull;
@ -10,8 +9,8 @@ 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))
fn new(brightness: val Brightness) -> move NonNull<GlobalBrightnessCommand> {
GlobalBrightnessCommand::from(brightness)
};
);

View file

@ -62,8 +62,8 @@ macro_rules! derive_command_into_packet {
#[doc = "Tries to turn a [`" $command_type "`] into a [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())
fn try_into_packet(move instance) -> move_ok *mut ::servicepoint::Packet {
instance.try_into()
};
);
}