move where the modifier is

This commit is contained in:
Vinzenz Schroeter 2025-06-23 21:36:01 +02:00
parent 5a849a87c7
commit 664625402f
10 changed files with 34 additions and 34 deletions

View file

@ -259,7 +259,7 @@ wrap_methods! { GenericCommand;
/// The [GenericCommand] gets consumed.
///
/// Returns tag [CommandTag::Invalid] in case of an error.
move fn try_into_packet(command) -> *mut Packet {
fn try_into_packet(move command) -> *mut Packet {
match command.tag {
CommandTag::Invalid => null_mut(),
CommandTag::Bitmap => {

View file

@ -71,7 +71,7 @@ macro_rules! derive_command_into_packet {
#[doc = "Tries to turn a [`" $command_type "`] into a [Packet]."]
///
/// Returns: NULL or a [Packet] containing the command.
move fn try_into_packet(instance) -> *mut ::servicepoint::Packet {
fn try_into_packet(move instance) -> *mut ::servicepoint::Packet {
$crate::mem::heap_move_ok(instance.try_into())
}
);

View file

@ -79,7 +79,7 @@ wrap_functions!(associate Bitmap;
wrap_methods!(Bitmap;
/// Consumes the Bitmap and returns the contained BitVec.
move fn into_bitvec(bitmap) -> NonNull<DisplayBitVec> {
fn into_bitvec(move bitmap) -> NonNull<DisplayBitVec> {
heap_move_nonnull(bitmap.into())
};
@ -88,7 +88,7 @@ wrap_methods!(Bitmap;
/// The provided [Bitmap] gets consumed.
///
/// Returns NULL in case of an error.
move fn try_into_packet(bitmap, x: usize, y: usize, compression: CompressionCode) -> *mut Packet {
fn try_into_packet(move bitmap, x: usize, y: usize, compression: CompressionCode) -> *mut Packet {
heap_move_ok(Packet::try_from(BitmapCommand {
bitmap,
origin: Origin::new(x, y),
@ -99,7 +99,7 @@ wrap_methods!(Bitmap;
/// Gets an unsafe reference to the data of the [Bitmap] instance.
///
/// The returned memory is valid for the lifetime of the bitmap.
mut fn data_ref_mut(instance) -> ByteSlice {
fn data_ref_mut(mut instance) -> ByteSlice {
unsafe { ByteSlice::from_slice(instance.data_ref_mut()) }
};
);

View file

@ -43,8 +43,8 @@ wrap_methods!(DisplayBitVec;
/// The provided [DisplayBitVec] gets consumed.
///
/// Returns NULL in case of an error.
move fn try_into_packet(
bitvec,
fn try_into_packet(
move bitvec,
offset: usize,
operation: BinaryOperation,
compression: CompressionCode
@ -69,7 +69,7 @@ wrap_methods!(DisplayBitVec;
/// # Panics
///
/// - when accessing `index` out of bounds
ref fn get(instance, index: usize) -> bool {
fn get(ref instance, index: usize) -> bool {
instance.get(index).map(|x| *x).unwrap_or(false)
};
@ -83,25 +83,25 @@ wrap_methods!(DisplayBitVec;
/// # Panics
///
/// - when accessing `index` out of bounds
mut fn set(instance, index: usize, value: bool);
fn set(mut instance, index: usize, value: bool);
/// Sets the value of all bits.
///
/// # Arguments
///
/// - `value`: the value to set all bits to
mut fn fill(instance, value: bool);
fn fill(mut instance, value: bool);
/// Gets the length in bits.
ref fn len(instance) -> usize;
fn len(ref instance) -> usize;
/// Returns true if length is 0.
ref fn is_empty(instance) -> bool;
fn is_empty(ref instance) -> bool;
/// Gets an unsafe reference to the data of the [DisplayBitVec] instance.
///
/// The returned memory is valid for the lifetime of the bitvec.
mut fn as_raw_mut_slice(instance) -> ByteSlice {
fn as_raw_mut_slice(mut instance) -> ByteSlice {
unsafe { ByteSlice::from_slice(instance.as_raw_mut_slice()) }
};
);

View file

@ -62,7 +62,7 @@ wrap_methods!(BrightnessGrid;
/// The provided [BrightnessGrid] gets consumed.
///
/// Returns NULL in case of an error.
move fn try_into_packet(grid, x: usize, y: usize) -> *mut Packet {
fn try_into_packet(move grid, x: usize, y: usize) -> *mut Packet {
heap_move_ok(Packet::try_from(BrightnessGridCommand {
grid,
origin: Origin::new(x, y),
@ -72,7 +72,7 @@ wrap_methods!(BrightnessGrid;
/// Gets an unsafe reference to the data of the instance.
///
/// The returned memory is valid for the lifetime of the grid.
mut fn data_ref_mut(instance) -> ByteSlice {
fn data_ref_mut(mut instance) -> ByteSlice {
//noinspection RsAssertEqual
const _: () = assert!(size_of::<Brightness>() == 1);

View file

@ -49,7 +49,7 @@ wrap_methods!(CharGrid;
/// # Panics
///
/// - when accessing `x` or `y` out of bounds
ref fn get(instance, x: usize, y: usize) -> u32 {
fn get(ref instance, x: usize, y: 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`.
mut fn set(instance, x: usize, y: usize, value: u32) {
fn set(mut instance, x: usize, y: usize, value: 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`.
mut fn fill(instance, value: u32) {
fn fill(mut instance, value: 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.
move fn try_into_packet(grid, x: usize, y: usize) -> *mut Packet {
fn try_into_packet(move grid, x: usize, y: usize) -> *mut Packet {
heap_move_ok(Packet::try_from(CharGridCommand {
grid,
origin: Origin::new(x, y),

View file

@ -31,7 +31,7 @@ wrap_methods!(Cp437Grid;
/// The provided [Cp437Grid] gets consumed.
///
/// Returns NULL in case of an error.
move fn try_into_packet(grid, x: usize, y: usize) -> *mut Packet {
fn try_into_packet(move grid, x: usize, y: usize) -> *mut Packet {
heap_move_ok(Packet::try_from(Cp437GridCommand {
grid,
origin: Origin::new(x, y),
@ -41,7 +41,7 @@ wrap_methods!(Cp437Grid;
/// Gets an unsafe reference to the data of the grid.
///
/// The returned memory is valid for the lifetime of the instance.
mut fn data_ref_mut(instance) -> ByteSlice {
fn data_ref_mut(mut instance) -> ByteSlice {
unsafe { ByteSlice::from_slice(instance.data_ref_mut()) }
};
);

View file

@ -23,10 +23,10 @@ macro_rules! derive_get_width_height {
($object_type:ident) => {
$crate::macros::wrap_methods! {$object_type;
/// Gets the width.
ref fn width(instance) -> usize;
fn width(ref instance) -> usize;
/// Gets the height.
ref fn height(instance) -> usize;
fn height(ref instance) -> usize;
}
};
}
@ -45,7 +45,7 @@ macro_rules! wrap_grid {
/// # Panics
///
/// - when accessing `x` or `y` out of bounds
ref fn get(instance, x: usize, y: usize) -> $value_type;
fn get(ref instance, x: usize, y: 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
mut fn set(instance, x: usize, y: usize, value: $value_type);
fn set(mut instance, x: usize, y: usize, value: $value_type);
/// Sets the state of all cells in the grid.
///
/// # Arguments
///
/// - `value`: the value to set all cells to
mut fn fill(instance, value: $value_type);
fn fill(mut instance, value: $value_type);
}
};
}

View file

@ -46,14 +46,14 @@ macro_rules! wrap_method {
(
$object_type:ident;
$(#[$meta:meta])+
$ref_or_mut:ident fn $function:ident($instance:ident $(, $($param_name:ident: $param_type:ty),*)?)
fn $function:ident($ref_or_mut:ident $instance:ident $(, $($param_name:ident: $param_type:ty),*)?)
$(-> $return_type:ty)?
) => {
::paste::paste!{
$crate::macros::wrap_method!(
$object_type;
$(#[$meta])+
$ref_or_mut fn $function($instance $(, $($param_name: $param_type),*)?)
fn $function($ref_or_mut $instance $(, $($param_name: $param_type),*)?)
$(-> $return_type)? {
$instance.$function($($($param_name),*)?)
}
@ -62,7 +62,7 @@ macro_rules! wrap_method {
};
($object_type:ident;
$(#[$meta:meta])+
$ref_or_mut:ident fn $function:ident($instance:ident $(, $($param_name:ident: $param_type:ty),*)?)
fn $function:ident($ref_or_mut:ident $instance:ident $(, $($param_name:ident: $param_type:ty),*)?)
$(-> $return_type:ty)?
$impl:block
) => {
@ -88,7 +88,7 @@ macro_rules! wrap_methods {
$object_type:ident;
$(
$(#[$meta:meta])+
$ref_or_mut:ident fn $function:ident($instance:ident $(, $($param_name:ident: $param_type:ty),*)?)
fn $function:ident($ref_or_mut:ident $instance:ident $(, $($param_name:ident: $param_type:ty),*)?)
$(-> $return_type:ty)?
$($impl:block)?;
)+
@ -97,7 +97,7 @@ macro_rules! wrap_methods {
$(
$crate::macros::wrap_method!($object_type;
$(#[$meta])*
$ref_or_mut fn $function($instance $(, $($param_name: $param_type),*)?)
fn $function($ref_or_mut $instance $(, $($param_name: $param_type),*)?)
$(-> $return_type)?
$($impl)?
);

View file

@ -57,7 +57,7 @@ wrap_methods! {UdpSocket;
/// The passed `packet` gets consumed.
///
/// returns: true in case of success
ref fn send_packet(connection, packet: NonNull<Packet>) -> bool {
fn send_packet(ref connection, packet: NonNull<Packet>) -> bool {
let packet = unsafe { heap_remove(packet) };
connection.send(&Vec::from(packet)).is_ok()
};
@ -73,7 +73,7 @@ wrap_methods! {UdpSocket;
/// ```C
/// sp_udp_send_command(connection, sp_command_brightness(5));
/// ```
ref fn send_command(connection, command: NonNull<GenericCommand>) -> bool {
fn send_command(ref connection, command: NonNull<GenericCommand>) -> bool {
unsafe {
let command = crate::macros::nonnull_as_mut!(command);
let result = match command.tag {
@ -103,7 +103,7 @@ wrap_methods! {UdpSocket;
/// ```C
/// sp_udp_send_header(connection, sp_command_brightness(5));
/// ```
ref fn send_header(udp_connection, header: Header) -> bool {
fn send_header(ref udp_connection, header: Header) -> bool {
let packet = Packet {
header,
payload: None,