add example for reading packages, fix functions return pointers to copy on stack

This commit is contained in:
Vinzenz Schroeter 2025-05-15 23:48:03 +02:00
parent 4ab5305377
commit 0c6efcee56
9 changed files with 86 additions and 10 deletions

View file

@ -65,7 +65,7 @@ pub unsafe extern "C" fn sp_cmd_bitvec_free(command: NonNull<BitVecCommand>) {
pub unsafe extern "C" fn sp_cmd_bitvec_get(
mut command: NonNull<BitVecCommand>,
) -> *mut DisplayBitVec {
&mut unsafe { command.as_mut() }.bitvec
unsafe { &mut command.as_mut().bitvec }
}
/// Moves the provided [BitVec] to be contained in the [BitVecCommand].

View file

@ -76,7 +76,7 @@ pub unsafe extern "C" fn sp_cmd_brightness_grid_set(
pub unsafe extern "C" fn sp_cmd_brightness_grid_get(
mut command: NonNull<BrightnessGridCommand>,
) -> *mut BrightnessGrid {
&mut unsafe { command.as_mut() }.grid
unsafe { &mut command.as_mut().grid }
}
/// Overwrites the origin field of the [BrightnessGridCommand].

View file

@ -74,7 +74,7 @@ pub unsafe extern "C" fn sp_cmd_char_grid_set(
pub unsafe extern "C" fn sp_cmd_char_grid_get(
mut command: NonNull<CharGridCommand>,
) -> *mut CharGrid {
&mut unsafe { command.as_mut() }.grid
unsafe { &mut command.as_mut().grid }
}
/// Reads the origin field of the [CharGridCommand].

View file

@ -83,7 +83,7 @@ pub unsafe extern "C" fn sp_cmd_cp437_grid_set(
pub unsafe extern "C" fn sp_cmd_cp437_grid_get(
mut command: NonNull<Cp437GridCommand>,
) -> *mut Cp437Grid {
&mut unsafe { command.as_mut() }.grid
unsafe { &mut command.as_mut().grid }
}
/// Gets the origin field of the [Cp437GridCommand].

View file

@ -53,5 +53,5 @@ pub unsafe extern "C" fn sp_cmd_brightness_global_set(
pub unsafe extern "C" fn sp_cmd_brightness_global_get(
mut command: NonNull<GlobalBrightnessCommand>,
) -> *mut Brightness {
&mut unsafe { command.as_mut() }.brightness
unsafe { &mut command.as_mut().brightness }
}

View file

@ -38,7 +38,7 @@ pub unsafe extern "C" fn sp_packet_from_parts(
pub unsafe extern "C" fn sp_packet_get_header(
packet: NonNull<Packet>,
) -> NonNull<Header> {
NonNull::from(&mut unsafe { (*packet.as_ptr()).header })
NonNull::from(unsafe { &mut (*packet.as_ptr()).header })
}
/// Returns a pointer to the current payload of the provided packet.