WIP: type per command #4

Draft
vinzenz wants to merge 49 commits from next into main
15 changed files with 59 additions and 59 deletions
Showing only changes of commit 514c0304b8 - Show all commits

View file

@ -45,8 +45,8 @@ pub unsafe extern "C" fn sp_cmd_bitmap_try_into_packet(
heap_move_ok(unsafe { heap_remove(command) }.try_into()) heap_move_ok(unsafe { heap_remove(command) }.try_into())
} }
wrap_clone!(BitmapCommand, sp_cmd_bitmap); wrap_clone!(sp_cmd_bitmap::BitmapCommand);
wrap_free!(BitmapCommand, sp_cmd_bitmap); wrap_free!(sp_cmd_bitmap::BitmapCommand);
/// Returns a pointer to the provided `BitmapCommand`. /// Returns a pointer to the provided `BitmapCommand`.
/// ///

View file

@ -45,8 +45,8 @@ pub unsafe extern "C" fn sp_cmd_bitvec_try_into_packet(
heap_move_ok(unsafe { heap_remove(command) }.try_into()) heap_move_ok(unsafe { heap_remove(command) }.try_into())
} }
wrap_clone!(BitVecCommand, sp_cmd_bitvec); wrap_clone!(sp_cmd_bitvec::BitVecCommand);
wrap_free!(BitVecCommand, sp_cmd_bitvec); wrap_free!(sp_cmd_bitvec::BitVecCommand);
/// Returns a pointer to the [BitVec] contained in the [BitVecCommand]. /// Returns a pointer to the [BitVec] contained in the [BitVecCommand].
#[no_mangle] #[no_mangle]

View file

@ -41,8 +41,8 @@ pub unsafe extern "C" fn sp_cmd_brightness_grid_into_packet(
heap_move_ok(unsafe { heap_remove(command) }.try_into()) heap_move_ok(unsafe { heap_remove(command) }.try_into())
} }
wrap_clone!(BrightnessGridCommand, sp_cmd_brightness_grid); wrap_clone!(sp_cmd_brightness_grid::BrightnessGridCommand);
wrap_free!(BrightnessGridCommand, sp_cmd_brightness_grid); wrap_free!(sp_cmd_brightness_grid::BrightnessGridCommand);
/// Moves the provided [BrightnessGrid] to be contained in the [BrightnessGridCommand]. /// Moves the provided [BrightnessGrid] to be contained in the [BrightnessGridCommand].
#[no_mangle] #[no_mangle]

View file

@ -12,7 +12,7 @@ pub unsafe extern "C" fn sp_cmd_clear_new() -> NonNull<ClearCommand> {
heap_move_nonnull(ClearCommand) heap_move_nonnull(ClearCommand)
} }
wrap_free!(ClearCommand, sp_cmd_clear); wrap_free!(sp_cmd_clear::ClearCommand);
/// Kills the udp daemon on the display, which usually results in a restart. /// Kills the udp daemon on the display, which usually results in a restart.
/// ///
@ -24,7 +24,7 @@ pub unsafe extern "C" fn sp_cmd_hard_reset_new() -> NonNull<HardResetCommand> {
heap_move_nonnull(HardResetCommand) heap_move_nonnull(HardResetCommand)
} }
wrap_free!(HardResetCommand, sp_cmd_hard_reset); wrap_free!(sp_cmd_hard_reset::HardResetCommand);
/// A yet-to-be-tested command. /// A yet-to-be-tested command.
/// ///
@ -34,4 +34,4 @@ pub unsafe extern "C" fn sp_cmd_fade_out_new() -> NonNull<FadeOutCommand> {
heap_move_nonnull(FadeOutCommand) heap_move_nonnull(FadeOutCommand)
} }
wrap_free!(FadeOutCommand, sp_cmd_fade_out); wrap_free!(sp_cmd_fade_out::FadeOutCommand);

View file

@ -41,8 +41,8 @@ pub unsafe extern "C" fn sp_cmd_char_grid_try_into_packet(
heap_move_ok(unsafe { heap_remove(command) }.try_into()) heap_move_ok(unsafe { heap_remove(command) }.try_into())
} }
wrap_clone!(CharGridCommand, sp_cmd_char_grid); wrap_clone!(sp_cmd_char_grid::CharGridCommand);
wrap_free!(CharGridCommand, sp_cmd_char_grid); wrap_free!(sp_cmd_char_grid::CharGridCommand);
/// Moves the provided [CharGrid] to be contained in the [CharGridCommand]. /// Moves the provided [CharGrid] to be contained in the [CharGridCommand].
#[no_mangle] #[no_mangle]

View file

@ -41,8 +41,8 @@ pub unsafe extern "C" fn sp_cmd_cp437_grid_try_into_packet(
heap_move_ok(unsafe { heap_remove(command) }.try_into()) heap_move_ok(unsafe { heap_remove(command) }.try_into())
} }
wrap_clone!(Cp437GridCommand, sp_cmd_cp437_grid); wrap_clone!(sp_cmd_cp437_grid::Cp437GridCommand);
wrap_free!(Cp437GridCommand, sp_cmd_cp437_grid); wrap_free!(sp_cmd_cp437_grid::Cp437GridCommand);
/// Moves the provided bitmap into the provided command. /// Moves the provided bitmap into the provided command.
/// ///

View file

@ -22,8 +22,8 @@ pub unsafe extern "C" fn sp_cmd_brightness_global_into_packet(
heap_move_nonnull(unsafe { heap_remove(command) }.into()) heap_move_nonnull(unsafe { heap_remove(command) }.into())
} }
wrap_clone!(GlobalBrightnessCommand, sp_cmd_brightness_global); wrap_clone!(sp_cmd_brightness_global::GlobalBrightnessCommand);
wrap_free!(GlobalBrightnessCommand, sp_cmd_brightness_global); wrap_free!(sp_cmd_brightness_global::GlobalBrightnessCommand);
/// Moves the provided bitmap to be contained in the command. /// Moves the provided bitmap to be contained in the command.
#[no_mangle] #[no_mangle]

View file

@ -80,11 +80,11 @@ pub unsafe extern "C" fn sp_bitmap_from_bitvec(
heap_move_ok(Bitmap::from_bitvec(width, bitvec)) heap_move_ok(Bitmap::from_bitvec(width, bitvec))
} }
wrap_clone!(Bitmap, sp_bitmap); wrap_clone!(sp_bitmap::Bitmap);
wrap_free!(Bitmap, sp_bitmap); wrap_free!(sp_bitmap::Bitmap);
wrap_method!( wrap_method!(
sp_bitmap :: Bitmap; sp_bitmap::Bitmap;
/// Gets the current value at the specified position. /// Gets the current value at the specified position.
/// ///
/// # Arguments /// # Arguments
@ -98,7 +98,7 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_bitmap :: Bitmap; sp_bitmap::Bitmap;
/// Sets the value of the specified position. /// Sets the value of the specified position.
/// ///
/// # Arguments /// # Arguments
@ -113,7 +113,7 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_bitmap :: Bitmap; sp_bitmap::Bitmap;
/// Sets the state of all pixels in the [Bitmap]. /// Sets the state of all pixels in the [Bitmap].
/// ///
/// # Arguments /// # Arguments
@ -123,19 +123,19 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_bitmap :: Bitmap; sp_bitmap::Bitmap;
/// Gets the width in pixels. /// Gets the width in pixels.
ref fn width() -> usize; ref fn width() -> usize;
); );
wrap_method!( wrap_method!(
sp_bitmap :: Bitmap; sp_bitmap::Bitmap;
/// Gets the height in pixels. /// Gets the height in pixels.
ref fn height() -> usize; ref fn height() -> usize;
); );
wrap_method!( wrap_method!(
sp_bitmap :: Bitmap; sp_bitmap::Bitmap;
/// Gets an unsafe reference to the data of the [Bitmap] instance. /// Gets an unsafe reference to the data of the [Bitmap] instance.
/// ///
/// The returned memory is valid for the lifetime of the bitmap. /// The returned memory is valid for the lifetime of the bitmap.

View file

@ -35,11 +35,11 @@ pub unsafe extern "C" fn sp_bitvec_load(
heap_move_nonnull(DisplayBitVec::from_slice(data)) heap_move_nonnull(DisplayBitVec::from_slice(data))
} }
wrap_clone!(DisplayBitVec, sp_bitvec); wrap_clone!(sp_bitvec::DisplayBitVec);
wrap_free!(DisplayBitVec, sp_bitvec); wrap_free!(sp_bitvec::DisplayBitVec);
wrap_method!( wrap_method!(
sp_bitvec :: DisplayBitVec; sp_bitvec::DisplayBitVec;
/// Gets the value of a bit. /// Gets the value of a bit.
/// ///
/// # Arguments /// # Arguments
@ -57,7 +57,7 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_bitvec :: DisplayBitVec; sp_bitvec::DisplayBitVec;
/// Sets the value of a bit. /// Sets the value of a bit.
/// ///
/// # Arguments /// # Arguments
@ -72,7 +72,7 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_bitvec :: DisplayBitVec; sp_bitvec::DisplayBitVec;
/// Sets the value of all bits. /// Sets the value of all bits.
/// ///
/// # Arguments /// # Arguments
@ -82,19 +82,19 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_bitvec :: DisplayBitVec; sp_bitvec::DisplayBitVec;
/// Gets the length in bits. /// Gets the length in bits.
ref fn len() -> usize; ref fn len() -> usize;
); );
wrap_method!( wrap_method!(
sp_bitvec :: DisplayBitVec; sp_bitvec::DisplayBitVec;
/// Returns true if length is 0. /// Returns true if length is 0.
ref fn is_empty() -> bool; ref fn is_empty() -> bool;
); );
wrap_method!( wrap_method!(
sp_bitvec :: DisplayBitVec; sp_bitvec::DisplayBitVec;
/// Gets an unsafe reference to the data of the [DisplayBitVec] instance. /// Gets an unsafe reference to the data of the [DisplayBitVec] instance.
/// ///
/// The returned memory is valid for the lifetime of the bitvec. /// The returned memory is valid for the lifetime of the bitvec.

View file

@ -52,11 +52,11 @@ pub unsafe extern "C" fn sp_brightness_grid_load(
) )
} }
wrap_clone!(BrightnessGrid, sp_brightness_grid); wrap_clone!(sp_brightness_grid::BrightnessGrid);
wrap_free!(BrightnessGrid, sp_brightness_grid); wrap_free!(sp_brightness_grid::BrightnessGrid);
wrap_method!( wrap_method!(
sp_brightness_grid :: BrightnessGrid; sp_brightness_grid::BrightnessGrid;
/// Gets the current value at the specified position. /// Gets the current value at the specified position.
/// ///
/// # Arguments /// # Arguments
@ -71,7 +71,7 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_brightness_grid :: BrightnessGrid; sp_brightness_grid::BrightnessGrid;
/// Sets the value of the specified position. /// Sets the value of the specified position.
/// ///
/// # Arguments /// # Arguments
@ -88,7 +88,7 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_brightness_grid :: BrightnessGrid; sp_brightness_grid::BrightnessGrid;
/// Sets the value of all cells. /// Sets the value of all cells.
/// ///
/// # Arguments /// # Arguments
@ -98,19 +98,19 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_brightness_grid :: BrightnessGrid; sp_brightness_grid::BrightnessGrid;
/// Gets the width of the grid. /// Gets the width of the grid.
ref fn width() -> usize; ref fn width() -> usize;
); );
wrap_method!( wrap_method!(
sp_brightness_grid :: BrightnessGrid; sp_brightness_grid::BrightnessGrid;
/// Gets the height of the grid. /// Gets the height of the grid.
ref fn height() -> usize; ref fn height() -> usize;
); );
wrap_method!( wrap_method!(
sp_brightness_grid :: BrightnessGrid; sp_brightness_grid::BrightnessGrid;
/// Gets an unsafe reference to the data of the instance. /// Gets an unsafe reference to the data of the instance.
/// ///
/// The returned memory is valid for the lifetime of the grid. /// The returned memory is valid for the lifetime of the grid.

View file

@ -39,11 +39,11 @@ pub unsafe extern "C" fn sp_char_grid_load(
heap_move_ok(CharGrid::load_utf8(width, height, data.to_vec())) heap_move_ok(CharGrid::load_utf8(width, height, data.to_vec()))
} }
wrap_clone!(CharGrid, sp_char_grid); wrap_clone!(sp_char_grid::CharGrid);
wrap_free!(CharGrid, sp_char_grid); wrap_free!(sp_char_grid::CharGrid);
wrap_method!( wrap_method!(
sp_char_grid :: CharGrid; sp_char_grid::CharGrid;
/// Returns the current value at the specified position. /// Returns the current value at the specified position.
/// ///
/// # Arguments /// # Arguments
@ -58,7 +58,7 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_char_grid :: CharGrid; sp_char_grid::CharGrid;
/// Sets the value of the specified position in the grid. /// Sets the value of the specified position in the grid.
/// ///
/// # Arguments /// # Arguments
@ -77,7 +77,7 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_char_grid :: CharGrid; sp_char_grid::CharGrid;
/// Sets the value of all cells in the grid. /// Sets the value of all cells in the grid.
/// ///
/// # Arguments /// # Arguments
@ -89,13 +89,13 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_char_grid :: CharGrid; sp_char_grid::CharGrid;
/// Gets the width of the grid. /// Gets the width of the grid.
ref fn width() -> usize; ref fn width() -> usize;
); );
wrap_method!( wrap_method!(
sp_char_grid :: CharGrid; sp_char_grid::CharGrid;
/// Gets the height of the grid. /// Gets the height of the grid.
ref fn height() -> usize; ref fn height() -> usize;
); );

View file

@ -30,11 +30,11 @@ pub unsafe extern "C" fn sp_cp437_grid_load(
heap_move_some(Cp437Grid::load(width, height, data)) heap_move_some(Cp437Grid::load(width, height, data))
} }
wrap_clone!(Cp437Grid, sp_cp437_grid); wrap_clone!(sp_cp437_grid::Cp437Grid);
wrap_free!(Cp437Grid, sp_cp437_grid); wrap_free!(sp_cp437_grid::Cp437Grid);
wrap_method!( wrap_method!(
sp_cp437 :: Cp437Grid; sp_cp437::Cp437Grid;
/// Gets the current value at the specified position. /// Gets the current value at the specified position.
/// ///
/// # Arguments /// # Arguments
@ -48,7 +48,7 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_cp437 :: Cp437Grid; sp_cp437::Cp437Grid;
/// Sets the value at the specified position. /// Sets the value at the specified position.
/// ///
/// # Arguments /// # Arguments
@ -65,7 +65,7 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_cp437 :: Cp437Grid; sp_cp437::Cp437Grid;
/// Sets the value of all cells in the grid. /// Sets the value of all cells in the grid.
/// ///
/// # Arguments /// # Arguments
@ -76,19 +76,19 @@ wrap_method!(
); );
wrap_method!( wrap_method!(
sp_cp437 :: Cp437Grid; sp_cp437::Cp437Grid;
/// Gets the width of the grid. /// Gets the width of the grid.
ref fn width() -> usize; ref fn width() -> usize;
); );
wrap_method!( wrap_method!(
sp_cp437 :: Cp437Grid; sp_cp437::Cp437Grid;
/// Gets the height of the grid. /// Gets the height of the grid.
ref fn height() -> usize; ref fn height() -> usize;
); );
wrap_method!( wrap_method!(
sp_cp437 :: Cp437Grid; sp_cp437::Cp437Grid;
/// Gets an unsafe reference to the data of the grid. /// Gets an unsafe reference to the data of the grid.
/// ///
/// The returned memory is valid for the lifetime of the instance. /// The returned memory is valid for the lifetime of the instance.

View file

@ -1,5 +1,5 @@
macro_rules! wrap_free { macro_rules! wrap_free {
($typ:ty, $prefix:ident) => { ($prefix:ident :: $typ:ty) => {
paste::paste! { paste::paste! {
#[doc = concat!("Deallocates a [", stringify!($typ), "] instance.")] #[doc = concat!("Deallocates a [", stringify!($typ), "] instance.")]
#[no_mangle] #[no_mangle]
@ -11,7 +11,7 @@ macro_rules! wrap_free {
} }
macro_rules! wrap_clone { macro_rules! wrap_clone {
($typ:ty, $prefix:ident) => { ($prefix:ident :: $typ:ty) => {
paste::paste! { paste::paste! {
#[doc = concat!("Clones a [", stringify!($typ), "] instance.")] #[doc = concat!("Clones a [", stringify!($typ), "] instance.")]
#[no_mangle] #[no_mangle]

View file

@ -91,8 +91,8 @@ pub unsafe extern "C" fn sp_packet_serialize_to(
} }
} }
wrap_clone!(Packet, sp_packet); wrap_clone!(sp_packet::Packet);
wrap_free!(Packet, sp_packet); wrap_free!(sp_packet::Packet);
/// Converts u16 into [CommandCode]. /// Converts u16 into [CommandCode].
/// ///

View file

@ -144,4 +144,4 @@ pub unsafe extern "C" fn sp_udp_send_header(
.is_ok() .is_ok()
} }
wrap_free!(UdpSocket, sp_udp); wrap_free!(sp_udp::UdpSocket);