From 664625402f88bac5aeb61b649b1f64ef55b3c0d3 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Mon, 23 Jun 2025 21:36:01 +0200 Subject: [PATCH] move where the modifier is --- src/commands/generic_command.rs | 2 +- src/commands/mod.rs | 2 +- src/containers/bitmap.rs | 6 +++--- src/containers/bitvec.rs | 16 ++++++++-------- src/containers/brightness_grid.rs | 4 ++-- src/containers/char_grid.rs | 8 ++++---- src/containers/cp437_grid.rs | 4 ++-- src/containers/mod.rs | 10 +++++----- src/macros.rs | 10 +++++----- src/udp.rs | 6 +++--- 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/commands/generic_command.rs b/src/commands/generic_command.rs index d288a27..dad7584 100644 --- a/src/commands/generic_command.rs +++ b/src/commands/generic_command.rs @@ -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 => { diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 74d22e3..026d0f1 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -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()) } ); diff --git a/src/containers/bitmap.rs b/src/containers/bitmap.rs index 738925b..4fb55a2 100644 --- a/src/containers/bitmap.rs +++ b/src/containers/bitmap.rs @@ -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 { + fn into_bitvec(move bitmap) -> NonNull { 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()) } }; ); diff --git a/src/containers/bitvec.rs b/src/containers/bitvec.rs index bc5da06..6ae2cf6 100644 --- a/src/containers/bitvec.rs +++ b/src/containers/bitvec.rs @@ -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()) } }; ); diff --git a/src/containers/brightness_grid.rs b/src/containers/brightness_grid.rs index 7c27d5c..a71a953 100644 --- a/src/containers/brightness_grid.rs +++ b/src/containers/brightness_grid.rs @@ -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::() == 1); diff --git a/src/containers/char_grid.rs b/src/containers/char_grid.rs index 1966f4a..a360a26 100644 --- a/src/containers/char_grid.rs +++ b/src/containers/char_grid.rs @@ -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), diff --git a/src/containers/cp437_grid.rs b/src/containers/cp437_grid.rs index 8905610..d4ed8a1 100644 --- a/src/containers/cp437_grid.rs +++ b/src/containers/cp437_grid.rs @@ -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()) } }; ); diff --git a/src/containers/mod.rs b/src/containers/mod.rs index fcd76a1..0a9eb38 100644 --- a/src/containers/mod.rs +++ b/src/containers/mod.rs @@ -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); } }; } diff --git a/src/macros.rs b/src/macros.rs index 768254b..d2b974c 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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)? ); diff --git a/src/udp.rs b/src/udp.rs index 7889937..aa307b0 100644 --- a/src/udp.rs +++ b/src/udp.rs @@ -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) -> bool { + fn send_packet(ref connection, packet: NonNull) -> 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) -> bool { + fn send_command(ref connection, command: NonNull) -> 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,