diff --git a/include/servicepoint.h b/include/servicepoint.h index 85f479d..4d77ba8 100644 --- a/include/servicepoint.h +++ b/include/servicepoint.h @@ -717,20 +717,6 @@ size_t sp_bitmap_height(struct Bitmap */*notnull*/ instance); */ BitVec */*notnull*/ sp_bitmap_into_bitvec(struct Bitmap */*notnull*/ bitmap); -/** - * Creates a [BitmapCommand] and immediately turns that into a [Packet]. - * - * The provided [Bitmap] gets consumed. - * - * Returns NULL in case of an error. - * - * This function is part of the `bitmap` module. - */ -struct Packet *sp_bitmap_into_packet(struct Bitmap */*notnull*/ bitmap, - size_t x, - size_t y, - CompressionCode compression); - /** * Loads a [Bitmap] with the specified dimensions from the provided data. * @@ -806,6 +792,20 @@ void sp_bitmap_set(struct Bitmap */*notnull*/ instance, size_t y, bool value); +/** + * Creates a [BitmapCommand] and immediately turns that into a [Packet]. + * + * The provided [Bitmap] gets consumed. + * + * Returns NULL in case of an error. + * + * This function is part of the `bitmap` module. + */ +struct Packet *sp_bitmap_try_into_packet(struct Bitmap */*notnull*/ bitmap, + size_t x, + size_t y, + CompressionCode compression); + /** * Calls method [`servicepoint::Bitmap::width`]. * @@ -1089,19 +1089,6 @@ Brightness sp_brightnessgrid_get(BrightnessGrid */*notnull*/ instance, */ size_t sp_brightnessgrid_height(BrightnessGrid */*notnull*/ instance); -/** - * Creates a [BrightnessGridCommand] and immediately turns that into a [Packet]. - * - * The provided [BrightnessGrid] gets consumed. - * - * Returns NULL in case of an error. - * - * This function is part of the `brightnessgrid` module. - */ -struct Packet *sp_brightnessgrid_into_packet(BrightnessGrid */*notnull*/ grid, - size_t x, - size_t y); - /** * Loads a [BrightnessGrid] with the specified dimensions from the provided data. * @@ -1159,6 +1146,19 @@ void sp_brightnessgrid_set(BrightnessGrid */*notnull*/ instance, size_t y, Brightness value); +/** + * Creates a [BrightnessGridCommand] and immediately turns that into a [Packet]. + * + * The provided [BrightnessGrid] gets consumed. + * + * Returns NULL in case of an error. + * + * This function is part of the `brightnessgrid` module. + */ +struct Packet *sp_brightnessgrid_try_into_packet(BrightnessGrid */*notnull*/ grid, + size_t x, + size_t y); + /** * Calls method [`servicepoint::BrightnessGrid::width`]. * @@ -1303,19 +1303,6 @@ uint32_t sp_chargrid_get(CharGrid */*notnull*/ instance, size_t x, size_t y); */ size_t sp_chargrid_height(CharGrid */*notnull*/ instance); -/** - * Creates a [CharGridCommand] and immediately turns that into a [Packet]. - * - * The provided [CharGrid] gets consumed. - * - * Returns NULL in case of an error. - * - * This function is part of the `chargrid` module. - */ -struct Packet *sp_chargrid_into_packet(CharGrid */*notnull*/ grid, - size_t x, - size_t y); - /** * Loads a [CharGrid] with the specified dimensions from the provided data. * @@ -1367,6 +1354,19 @@ void sp_chargrid_set(CharGrid */*notnull*/ instance, size_t y, uint32_t value); +/** + * Creates a [CharGridCommand] and immediately turns that into a [Packet]. + * + * The provided [CharGrid] gets consumed. + * + * Returns NULL in case of an error. + * + * This function is part of the `chargrid` module. + */ +struct Packet *sp_chargrid_try_into_packet(CharGrid */*notnull*/ grid, + size_t x, + size_t y); + /** * Calls method [`servicepoint::CharGrid::width`]. * @@ -1622,19 +1622,6 @@ uint8_t sp_cp437grid_get(Cp437Grid */*notnull*/ instance, size_t x, size_t y); */ size_t sp_cp437grid_height(Cp437Grid */*notnull*/ instance); -/** - * Creates a [Cp437GridCommand] and immediately turns that into a [Packet]. - * - * The provided [Cp437Grid] gets consumed. - * - * Returns NULL in case of an error. - * - * This function is part of the `cp437grid` module. - */ -struct Packet *sp_cp437grid_into_packet(Cp437Grid */*notnull*/ grid, - size_t x, - size_t y); - /** * Loads a [Cp437Grid] with the specified dimensions from the provided data. * @@ -1674,6 +1661,19 @@ void sp_cp437grid_set(Cp437Grid */*notnull*/ instance, size_t y, uint8_t value); +/** + * Creates a [Cp437GridCommand] and immediately turns that into a [Packet]. + * + * The provided [Cp437Grid] gets consumed. + * + * Returns NULL in case of an error. + * + * This function is part of the `cp437grid` module. + */ +struct Packet *sp_cp437grid_try_into_packet(Cp437Grid */*notnull*/ grid, + size_t x, + size_t y); + /** * Calls method [`servicepoint::Cp437Grid::width`]. * @@ -1801,20 +1801,6 @@ void sp_displaybitvec_free(BitVec */*notnull*/ instance); */ bool sp_displaybitvec_get(BitVec */*notnull*/ instance, size_t index); -/** - * Creates a [BitVecCommand] and immediately turns that into a [Packet]. - * - * The provided [DisplayBitVec] gets consumed. - * - * Returns NULL in case of an error. - * - * This function is part of the `displaybitvec` module. - */ -struct Packet *sp_displaybitvec_into_packet(BitVec */*notnull*/ bitvec, - size_t offset, - BinaryOperation operation, - CompressionCode compression); - /** * Calls method [`servicepoint::DisplayBitVec::is_empty`]. * @@ -1879,6 +1865,20 @@ void sp_displaybitvec_set(BitVec */*notnull*/ instance, size_t index, bool value); +/** + * Creates a [BitVecCommand] and immediately turns that into a [Packet]. + * + * The provided [DisplayBitVec] gets consumed. + * + * Returns NULL in case of an error. + * + * This function is part of the `displaybitvec` module. + */ +struct Packet *sp_displaybitvec_try_into_packet(BitVec */*notnull*/ bitvec, + size_t offset, + BinaryOperation operation, + CompressionCode compression); + /** * Call this function at the beginning of main to enable rust logging controlled by the * `RUST_LOG` environment variable. See [env_logger](https://docs.rs/env_logger/latest/env_logger/). diff --git a/src/commands/cc_only_commands.rs b/src/commands/cc_only_commands.rs index a34e5c8..6635ae9 100644 --- a/src/commands/cc_only_commands.rs +++ b/src/commands/cc_only_commands.rs @@ -2,7 +2,6 @@ use crate::{ commands::wrap_command, macros::wrap_functions, mem::heap_move_nonnull, }; use servicepoint::{ClearCommand, FadeOutCommand, HardResetCommand}; -use std::ptr::NonNull; macro_rules! wrap_cc_only { ($(#[$meta:meta])* $command:ident) => { @@ -13,7 +12,7 @@ macro_rules! wrap_cc_only { $(#[$meta])* /// #[doc = " Returns: a new [`" [< $command Command >] "`] instance."] - fn new() -> NonNull<[< $command Command >]> { + fn new() -> ::core::ptr::NonNull<[< $command Command >]> { heap_move_nonnull([< $command Command >]) } ); diff --git a/src/commands/mod.rs b/src/commands/mod.rs index e15ba1f..9da0a22 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -20,9 +20,9 @@ macro_rules! wrap_origin_accessors { $crate::macros::wrap_functions!(associate $object_type; #[doc = " Reads the origin field of the [`" $object_type "`]."] fn get_origin( - command: NonNull<$object_type>, - origin_x: NonNull, - origin_y: NonNull, + command: ::core::ptr::NonNull<$object_type>, + origin_x: ::core::ptr::NonNull, + origin_y: ::core::ptr::NonNull, ) { unsafe { let origin = &command.as_ref().origin; @@ -33,7 +33,7 @@ macro_rules! wrap_origin_accessors { #[doc = " Overwrites the origin field of the [`" $object_type "`]."] fn set_origin( - command: NonNull<$object_type>, + command: ::core::ptr::NonNull<$object_type>, origin_x: usize, origin_y: usize, ) { @@ -72,7 +72,7 @@ macro_rules! derive_command_into_packet { /// /// Returns: NULL or a [Packet] containing the command. fn try_into_packet( - command: NonNull<$command_type>, + command: ::core::ptr::NonNull<$command_type>, ) -> *mut ::servicepoint::Packet { $crate::mem::heap_move_ok(unsafe { $crate::mem::heap_remove(command) }.try_into()) } diff --git a/src/containers/bitmap.rs b/src/containers/bitmap.rs index b7e3a09..ffda27e 100644 --- a/src/containers/bitmap.rs +++ b/src/containers/bitmap.rs @@ -89,7 +89,7 @@ wrap_functions!(bitmap; /// The provided [Bitmap] gets consumed. /// /// Returns NULL in case of an error. - fn into_packet( + fn try_into_packet( bitmap: NonNull, x: usize, y: usize, diff --git a/src/containers/bitvec.rs b/src/containers/bitvec.rs index 6db5e6d..1549d60 100644 --- a/src/containers/bitvec.rs +++ b/src/containers/bitvec.rs @@ -40,7 +40,7 @@ wrap_functions!(associate DisplayBitVec; /// The provided [DisplayBitVec] gets consumed. /// /// Returns NULL in case of an error. - fn into_packet( + fn try_into_packet( bitvec: NonNull, offset: usize, operation: BinaryOperation, diff --git a/src/containers/brightness_grid.rs b/src/containers/brightness_grid.rs index a7854e3..033bbdd 100644 --- a/src/containers/brightness_grid.rs +++ b/src/containers/brightness_grid.rs @@ -59,7 +59,7 @@ wrap_functions!(associate BrightnessGrid; /// The provided [BrightnessGrid] gets consumed. /// /// Returns NULL in case of an error. - fn into_packet( + fn try_into_packet( grid: NonNull, x: usize, y: usize, diff --git a/src/containers/char_grid.rs b/src/containers/char_grid.rs index 6cc8a4a..365f1ad 100644 --- a/src/containers/char_grid.rs +++ b/src/containers/char_grid.rs @@ -47,7 +47,7 @@ wrap_functions!(associate CharGrid; /// The provided [CharGrid] gets consumed. /// /// Returns NULL in case of an error. - fn into_packet( + fn try_into_packet( grid: NonNull, x: usize, y: usize, diff --git a/src/containers/cp437_grid.rs b/src/containers/cp437_grid.rs index f25a502..001ebb8 100644 --- a/src/containers/cp437_grid.rs +++ b/src/containers/cp437_grid.rs @@ -37,7 +37,7 @@ wrap_functions!(cp437grid; /// The provided [Cp437Grid] gets consumed. /// /// Returns NULL in case of an error. - fn into_packet( + fn try_into_packet( grid: NonNull, x: usize, y: usize, diff --git a/src/macros.rs b/src/macros.rs index f737205..20259fc 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -3,7 +3,7 @@ macro_rules! derive_free { ::paste::paste! { $crate::macros::wrap_functions!([< $typ:lower >]; #[doc = "Deallocates a [`" $typ "`] instance."] - fn free(instance: NonNull<$typ>) { + fn free(instance: ::core::ptr::NonNull<$typ>) { unsafe { $crate::mem::heap_drop(instance) } } ); @@ -16,7 +16,7 @@ macro_rules! derive_clone { ::paste::paste! { $crate::macros::wrap_functions!([< $typ:lower >]; #[doc = "Clones a [`" $typ "`] instance."] - fn clone(instance: NonNull<$typ>) -> NonNull<$typ> { + fn clone(instance: ::core::ptr::NonNull<$typ>) -> ::core::ptr::NonNull<$typ> { unsafe { $crate::mem::heap_clone(instance) } } ); @@ -58,7 +58,7 @@ macro_rules! wrap_methods { #[doc = ""] $(#[$meta])* fn $function( - instance: NonNull<$object_type>, + instance: ::core::ptr::NonNull<$object_type>, $($param_name: $param_type),* ) $(-> $return_type)? { let instance = unsafe { $crate::macros:: [< nonnull_as_ $ref_or_mut >] !(instance) }; @@ -192,7 +192,7 @@ macro_rules! wrap_fields { )*)? fn []( instance: ::core::ptr::NonNull<$object_type>, - value: NonNull<$prop_type>, + value: ::core::ptr::NonNull<$prop_type>, ) { let instance = unsafe { $crate::macros::nonnull_as_mut!(instance) }; let value = unsafe { $crate::mem::heap_remove(value) };