From 21987d05f37ab5696b3fbbffe794507df65f1ce9 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Wed, 18 Jun 2025 20:41:22 +0200 Subject: [PATCH] use macros in macros --- include/servicepoint.h | 218 +++++++++++++++++++++++++++++++++-------- src/macros.rs | 141 +++++++++++++------------- 2 files changed, 248 insertions(+), 111 deletions(-) diff --git a/include/servicepoint.h b/include/servicepoint.h index 5960987..e001ddd 100644 --- a/include/servicepoint.h +++ b/include/servicepoint.h @@ -640,7 +640,9 @@ extern "C" { void init_env_logger(void); /** - *Clones a [Bitmap] instance. + *Clones a [`Bitmap`] instance. + * + * This function is part of the sp_bitmap module. */ struct Bitmap */*notnull*/ sp_bitmap_clone(struct Bitmap */*notnull*/ instance); @@ -650,6 +652,8 @@ struct Bitmap */*notnull*/ sp_bitmap_clone(struct Bitmap */*notnull*/ instance); * Gets an unsafe reference to the data of the [Bitmap] instance. * * The returned memory is valid for the lifetime of the bitmap. + * + * This function is part of the sp_bitmap module. */ struct ByteSlice sp_bitmap_data_ref_mut(struct Bitmap */*notnull*/ instance); @@ -661,11 +665,15 @@ struct ByteSlice sp_bitmap_data_ref_mut(struct Bitmap */*notnull*/ instance); * # Arguments * * - `value`: the value to set all pixels to + * + * This function is part of the sp_bitmap module. */ void sp_bitmap_fill(struct Bitmap */*notnull*/ instance, bool value); /** - *Deallocates a [Bitmap] instance. + *Deallocates a [`Bitmap`] instance. + * + * This function is part of the sp_bitmap module. */ void sp_bitmap_free(struct Bitmap */*notnull*/ instance); @@ -692,6 +700,8 @@ struct Bitmap *sp_bitmap_from_bitvec(size_t width, BitVec */*notnull*/ bitvec); * # Panics * * - when accessing `x` or `y` out of bounds + * + * This function is part of the sp_bitmap module. */ bool sp_bitmap_get(struct Bitmap */*notnull*/ instance, size_t x, size_t y); @@ -699,6 +709,8 @@ bool sp_bitmap_get(struct Bitmap */*notnull*/ instance, size_t x, size_t y); * Calls [`servicepoint::Bitmap::height`]. * * Gets the height in pixels. + * + * This function is part of the sp_bitmap module. */ size_t sp_bitmap_height(struct Bitmap */*notnull*/ instance); @@ -790,6 +802,8 @@ struct Bitmap */*notnull*/ sp_bitmap_new_max_sized(void); * # Panics * * - when accessing `x` or `y` out of bounds + * + * This function is part of the sp_bitmap module. */ void sp_bitmap_set(struct Bitmap */*notnull*/ instance, size_t x, @@ -800,6 +814,8 @@ void sp_bitmap_set(struct Bitmap */*notnull*/ instance, * Calls [`servicepoint::Bitmap::width`]. * * Gets the width in pixels. + * + * This function is part of the sp_bitmap module. */ size_t sp_bitmap_width(struct Bitmap */*notnull*/ instance); @@ -809,11 +825,15 @@ size_t sp_bitmap_width(struct Bitmap */*notnull*/ instance); * Gets an unsafe reference to the data of the [DisplayBitVec] instance. * * The returned memory is valid for the lifetime of the bitvec. + * + * This function is part of the sp_bitvec module. */ struct ByteSlice sp_bitvec_as_raw_mut_slice(BitVec */*notnull*/ instance); /** - *Clones a [DisplayBitVec] instance. + *Clones a [`DisplayBitVec`] instance. + * + * This function is part of the sp_bitvec module. */ BitVec */*notnull*/ sp_bitvec_clone(BitVec */*notnull*/ instance); @@ -825,11 +845,15 @@ BitVec */*notnull*/ sp_bitvec_clone(BitVec */*notnull*/ instance); * # Arguments * * - `value`: the value to set all bits to + * + * This function is part of the sp_bitvec module. */ void sp_bitvec_fill(BitVec */*notnull*/ instance, bool value); /** - *Deallocates a [DisplayBitVec] instance. + *Deallocates a [`DisplayBitVec`] instance. + * + * This function is part of the sp_bitvec module. */ void sp_bitvec_free(BitVec */*notnull*/ instance); @@ -848,6 +872,8 @@ void sp_bitvec_free(BitVec */*notnull*/ instance); * # Panics * * - when accessing `index` out of bounds + * + * This function is part of the sp_bitvec module. */ bool sp_bitvec_get(BitVec */*notnull*/ instance, size_t index); @@ -869,6 +895,8 @@ struct Packet *sp_bitvec_into_packet(BitVec */*notnull*/ bitvec, * Calls [`servicepoint::DisplayBitVec::is_empty`]. * * Returns true if length is 0. + * + * This function is part of the sp_bitvec module. */ bool sp_bitvec_is_empty(BitVec */*notnull*/ instance); @@ -876,6 +904,8 @@ bool sp_bitvec_is_empty(BitVec */*notnull*/ instance); * Calls [`servicepoint::DisplayBitVec::len`]. * * Gets the length in bits. + * + * This function is part of the sp_bitvec module. */ size_t sp_bitvec_len(BitVec */*notnull*/ instance); @@ -918,11 +948,15 @@ BitVec */*notnull*/ sp_bitvec_new(size_t size); * # Panics * * - when accessing `index` out of bounds + * + * This function is part of the sp_bitvec module. */ void sp_bitvec_set(BitVec */*notnull*/ instance, size_t index, bool value); /** - *Clones a [BrightnessGrid] instance. + *Clones a [`BrightnessGrid`] instance. + * + * This function is part of the sp_brightness_grid module. */ BrightnessGrid */*notnull*/ sp_brightness_grid_clone(BrightnessGrid */*notnull*/ instance); @@ -932,6 +966,8 @@ BrightnessGrid */*notnull*/ sp_brightness_grid_clone(BrightnessGrid */*notnull*/ * Gets an unsafe reference to the data of the instance. * * The returned memory is valid for the lifetime of the grid. + * + * This function is part of the sp_brightness_grid module. */ struct ByteSlice sp_brightness_grid_data_ref_mut(BrightnessGrid */*notnull*/ instance); @@ -943,12 +979,16 @@ struct ByteSlice sp_brightness_grid_data_ref_mut(BrightnessGrid */*notnull*/ ins * # Arguments * * - `value`: the value to set all cells to + * + * This function is part of the sp_brightness_grid module. */ void sp_brightness_grid_fill(BrightnessGrid */*notnull*/ instance, Brightness value); /** - *Deallocates a [BrightnessGrid] instance. + *Deallocates a [`BrightnessGrid`] instance. + * + * This function is part of the sp_brightness_grid module. */ void sp_brightness_grid_free(BrightnessGrid */*notnull*/ instance); @@ -965,6 +1005,8 @@ void sp_brightness_grid_free(BrightnessGrid */*notnull*/ instance); * * # Panics * - When accessing `x` or `y` out of bounds. + * + * This function is part of the sp_brightness_grid module. */ Brightness sp_brightness_grid_get(BrightnessGrid */*notnull*/ instance, size_t x, @@ -974,6 +1016,8 @@ Brightness sp_brightness_grid_get(BrightnessGrid */*notnull*/ instance, * Calls [`servicepoint::BrightnessGrid::height`]. * * Gets the height of the grid. + * + * This function is part of the sp_brightness_grid module. */ size_t sp_brightness_grid_height(BrightnessGrid */*notnull*/ instance); @@ -1041,6 +1085,8 @@ BrightnessGrid */*notnull*/ sp_brightness_grid_new(size_t width, size_t height); * # Panics * * - When accessing `x` or `y` out of bounds. + * + * This function is part of the sp_brightness_grid module. */ void sp_brightness_grid_set(BrightnessGrid */*notnull*/ instance, size_t x, @@ -1051,11 +1097,15 @@ void sp_brightness_grid_set(BrightnessGrid */*notnull*/ instance, * Calls [`servicepoint::BrightnessGrid::width`]. * * Gets the width of the grid. + * + * This function is part of the sp_brightness_grid module. */ size_t sp_brightness_grid_width(BrightnessGrid */*notnull*/ instance); /** - *Clones a [CharGrid] instance. + *Clones a [`CharGrid`] instance. + * + * This function is part of the sp_char_grid module. */ CharGrid */*notnull*/ sp_char_grid_clone(CharGrid */*notnull*/ instance); @@ -1068,11 +1118,15 @@ CharGrid */*notnull*/ sp_char_grid_clone(CharGrid */*notnull*/ instance); * * - `value`: the value to set all cells to * - when providing values that cannot be converted to Rust's `char`. + * + * This function is part of the sp_char_grid module. */ void sp_char_grid_fill(CharGrid */*notnull*/ instance, uint32_t value); /** - *Deallocates a [CharGrid] instance. + *Deallocates a [`CharGrid`] instance. + * + * This function is part of the sp_char_grid module. */ void sp_char_grid_free(CharGrid */*notnull*/ instance); @@ -1088,6 +1142,8 @@ void sp_char_grid_free(CharGrid */*notnull*/ instance); * # Panics * * - when accessing `x` or `y` out of bounds + * + * This function is part of the sp_char_grid module. */ uint32_t sp_char_grid_get(CharGrid */*notnull*/ instance, size_t x, size_t y); @@ -1095,6 +1151,8 @@ uint32_t sp_char_grid_get(CharGrid */*notnull*/ instance, size_t x, size_t y); * Calls [`servicepoint::CharGrid::height`]. * * Gets the height of the grid. + * + * This function is part of the sp_char_grid module. */ size_t sp_char_grid_height(CharGrid */*notnull*/ instance); @@ -1154,6 +1212,8 @@ CharGrid */*notnull*/ sp_char_grid_new(size_t width, size_t height); * * - when accessing `x` or `y` out of bounds * - when providing values that cannot be converted to Rust's `char`. + * + * This function is part of the sp_char_grid module. */ void sp_char_grid_set(CharGrid */*notnull*/ instance, size_t x, @@ -1164,16 +1224,22 @@ void sp_char_grid_set(CharGrid */*notnull*/ instance, * Calls [`servicepoint::CharGrid::width`]. * * Gets the width of the grid. + * + * This function is part of the sp_char_grid module. */ size_t sp_char_grid_width(CharGrid */*notnull*/ instance); /** - *Clones a [BitmapCommand] instance. + *Clones a [`BitmapCommand`] instance. + * + * This function is part of the sp_cmd_bitmap module. */ struct BitmapCommand */*notnull*/ sp_cmd_bitmap_clone(struct BitmapCommand */*notnull*/ instance); /** - *Deallocates a [BitmapCommand] instance. + *Deallocates a [`BitmapCommand`] instance. + * + * This function is part of the sp_cmd_bitmap module. */ void sp_cmd_bitmap_free(struct BitmapCommand */*notnull*/ instance); @@ -1198,7 +1264,9 @@ struct BitmapCommand */*notnull*/ sp_cmd_bitmap_from_bitmap(struct Bitmap */*not struct Bitmap */*notnull*/ sp_cmd_bitmap_get(struct BitmapCommand */*notnull*/ command); /** - *Gets the value of field `compression` of the [`servicepoint::BitmapCommand`]. + * Gets the value of field `compression` of the [`servicepoint::BitmapCommand`]. + * + * This function is part of the sp_cmd_bitmap module. */ CompressionCode sp_cmd_bitmap_get_compression(struct BitmapCommand */*notnull*/ instance); @@ -1230,7 +1298,9 @@ void sp_cmd_bitmap_set(struct BitmapCommand */*notnull*/ command, struct Bitmap */*notnull*/ bitmap); /** - *Sets the value of field `compression` of the [`servicepoint::BitmapCommand`]. + * Sets the value of field `compression` of the [`servicepoint::BitmapCommand`]. + * + * This function is part of the sp_cmd_bitmap module. */ void sp_cmd_bitmap_set_compression(struct BitmapCommand */*notnull*/ instance, CompressionCode value); @@ -1252,12 +1322,16 @@ void sp_cmd_bitmap_set_origin(struct BitmapCommand */*notnull*/ command, struct Packet *sp_cmd_bitmap_try_into_packet(struct BitmapCommand */*notnull*/ command); /** - *Clones a [BitVecCommand] instance. + *Clones a [`BitVecCommand`] instance. + * + * This function is part of the sp_cmd_bitvec module. */ struct BitVecCommand */*notnull*/ sp_cmd_bitvec_clone(struct BitVecCommand */*notnull*/ instance); /** - *Deallocates a [BitVecCommand] instance. + *Deallocates a [`BitVecCommand`] instance. + * + * This function is part of the sp_cmd_bitvec module. */ void sp_cmd_bitvec_free(struct BitVecCommand */*notnull*/ instance); @@ -1267,17 +1341,23 @@ void sp_cmd_bitvec_free(struct BitVecCommand */*notnull*/ instance); BitVec *sp_cmd_bitvec_get(struct BitVecCommand */*notnull*/ command); /** - *Gets the value of field `compression` of the [`servicepoint::BitVecCommand`]. + * Gets the value of field `compression` of the [`servicepoint::BitVecCommand`]. + * + * This function is part of the sp_cmd_bitvec module. */ CompressionCode sp_cmd_bitvec_get_compression(struct BitVecCommand */*notnull*/ instance); /** - *Gets the value of field `offset` of the [`servicepoint::BitVecCommand`]. + * Gets the value of field `offset` of the [`servicepoint::BitVecCommand`]. + * + * This function is part of the sp_cmd_bitvec module. */ Offset sp_cmd_bitvec_get_offset(struct BitVecCommand */*notnull*/ instance); /** - *Gets the value of field `operation` of the [`servicepoint::BitVecCommand`]. + * Gets the value of field `operation` of the [`servicepoint::BitVecCommand`]. + * + * This function is part of the sp_cmd_bitvec module. */ BinaryOperation sp_cmd_bitvec_get_operation(struct BitVecCommand */*notnull*/ instance); @@ -1309,19 +1389,25 @@ void sp_cmd_bitvec_set(struct BitVecCommand */*notnull*/ command, BitVec */*notnull*/ bitvec); /** - *Sets the value of field `compression` of the [`servicepoint::BitVecCommand`]. + * Sets the value of field `compression` of the [`servicepoint::BitVecCommand`]. + * + * This function is part of the sp_cmd_bitvec module. */ void sp_cmd_bitvec_set_compression(struct BitVecCommand */*notnull*/ instance, CompressionCode value); /** - *Sets the value of field `offset` of the [`servicepoint::BitVecCommand`]. + * Sets the value of field `offset` of the [`servicepoint::BitVecCommand`]. + * + * This function is part of the sp_cmd_bitvec module. */ void sp_cmd_bitvec_set_offset(struct BitVecCommand */*notnull*/ instance, Offset value); /** - *Sets the value of field `operation` of the [`servicepoint::BitVecCommand`]. + * Sets the value of field `operation` of the [`servicepoint::BitVecCommand`]. + * + * This function is part of the sp_cmd_bitvec module. */ void sp_cmd_bitvec_set_operation(struct BitVecCommand */*notnull*/ instance, BinaryOperation value); @@ -1336,17 +1422,23 @@ void sp_cmd_bitvec_set_operation(struct BitVecCommand */*notnull*/ instance, struct Packet *sp_cmd_bitvec_try_into_packet(struct BitVecCommand */*notnull*/ command); /** - *Clones a [GlobalBrightnessCommand] instance. + *Clones a [`GlobalBrightnessCommand`] instance. + * + * This function is part of the sp_cmd_brightness_global module. */ struct GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_clone(struct GlobalBrightnessCommand */*notnull*/ instance); /** - *Deallocates a [GlobalBrightnessCommand] instance. + *Deallocates a [`GlobalBrightnessCommand`] instance. + * + * This function is part of the sp_cmd_brightness_global module. */ void sp_cmd_brightness_global_free(struct GlobalBrightnessCommand */*notnull*/ instance); /** - *Gets the value of field `brightness` of the [`servicepoint::GlobalBrightnessCommand`]. + * Gets the value of field `brightness` of the [`servicepoint::GlobalBrightnessCommand`]. + * + * This function is part of the sp_cmd_brightness_global module. */ Brightness sp_cmd_brightness_global_get_brightness(struct GlobalBrightnessCommand */*notnull*/ instance); @@ -1367,18 +1459,24 @@ struct Packet */*notnull*/ sp_cmd_brightness_global_into_packet(struct GlobalBri struct GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_new(Brightness brightness); /** - *Sets the value of field `brightness` of the [`servicepoint::GlobalBrightnessCommand`]. + * Sets the value of field `brightness` of the [`servicepoint::GlobalBrightnessCommand`]. + * + * This function is part of the sp_cmd_brightness_global module. */ void sp_cmd_brightness_global_set_brightness(struct GlobalBrightnessCommand */*notnull*/ instance, Brightness value); /** - *Clones a [BrightnessGridCommand] instance. + *Clones a [`BrightnessGridCommand`] instance. + * + * This function is part of the sp_cmd_brightness_grid module. */ struct BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_clone(struct BrightnessGridCommand */*notnull*/ instance); /** - *Deallocates a [BrightnessGridCommand] instance. + *Deallocates a [`BrightnessGridCommand`] instance. + * + * This function is part of the sp_cmd_brightness_grid module. */ void sp_cmd_brightness_grid_free(struct BrightnessGridCommand */*notnull*/ instance); @@ -1438,12 +1536,16 @@ void sp_cmd_brightness_grid_set_origin(struct BrightnessGridCommand */*notnull*/ size_t origin_y); /** - *Clones a [CharGridCommand] instance. + *Clones a [`CharGridCommand`] instance. + * + * This function is part of the sp_cmd_char_grid module. */ struct CharGridCommand */*notnull*/ sp_cmd_char_grid_clone(struct CharGridCommand */*notnull*/ instance); /** - *Deallocates a [CharGridCommand] instance. + *Deallocates a [`CharGridCommand`] instance. + * + * This function is part of the sp_cmd_char_grid module. */ void sp_cmd_char_grid_free(struct CharGridCommand */*notnull*/ instance); @@ -1503,7 +1605,9 @@ void sp_cmd_char_grid_set_origin(struct CharGridCommand */*notnull*/ command, struct Packet *sp_cmd_char_grid_try_into_packet(struct CharGridCommand */*notnull*/ command); /** - *Deallocates a [ClearCommand] instance. + *Deallocates a [`ClearCommand`] instance. + * + * This function is part of the sp_cmd_clear module. */ void sp_cmd_clear_free(struct ClearCommand */*notnull*/ instance); @@ -1519,12 +1623,16 @@ void sp_cmd_clear_free(struct ClearCommand */*notnull*/ instance); struct ClearCommand */*notnull*/ sp_cmd_clear_new(void); /** - *Clones a [Cp437GridCommand] instance. + *Clones a [`Cp437GridCommand`] instance. + * + * This function is part of the sp_cmd_cp437_grid module. */ struct Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_clone(struct Cp437GridCommand */*notnull*/ instance); /** - *Deallocates a [Cp437GridCommand] instance. + *Deallocates a [`Cp437GridCommand`] instance. + * + * This function is part of the sp_cmd_cp437_grid module. */ void sp_cmd_cp437_grid_free(struct Cp437GridCommand */*notnull*/ instance); @@ -1595,7 +1703,9 @@ void sp_cmd_cp437_grid_set_origin(struct Cp437GridCommand */*notnull*/ command, struct Packet *sp_cmd_cp437_grid_try_into_packet(struct Cp437GridCommand */*notnull*/ command); /** - *Deallocates a [FadeOutCommand] instance. + *Deallocates a [`FadeOutCommand`] instance. + * + * This function is part of the sp_cmd_fade_out module. */ void sp_cmd_fade_out_free(struct FadeOutCommand */*notnull*/ instance); @@ -1647,7 +1757,9 @@ struct Packet *sp_cmd_generic_into_packet(struct Command command); struct Command sp_cmd_generic_try_from_packet(struct Packet */*notnull*/ packet); /** - *Deallocates a [HardResetCommand] instance. + *Deallocates a [`HardResetCommand`] instance. + * + * This function is part of the sp_cmd_hard_reset module. */ void sp_cmd_hard_reset_free(struct HardResetCommand */*notnull*/ instance); @@ -1663,7 +1775,9 @@ void sp_cmd_hard_reset_free(struct HardResetCommand */*notnull*/ instance); struct HardResetCommand */*notnull*/ sp_cmd_hard_reset_new(void); /** - *Clones a [Cp437Grid] instance. + *Clones a [`Cp437Grid`] instance. + * + * This function is part of the sp_cp437_grid module. */ Cp437Grid */*notnull*/ sp_cp437_grid_clone(Cp437Grid */*notnull*/ instance); @@ -1673,6 +1787,8 @@ Cp437Grid */*notnull*/ sp_cp437_grid_clone(Cp437Grid */*notnull*/ instance); * Gets an unsafe reference to the data of the grid. * * The returned memory is valid for the lifetime of the instance. + * + * This function is part of the sp_cp437_grid module. */ struct ByteSlice sp_cp437_grid_data_ref_mut(Cp437Grid */*notnull*/ instance); @@ -1685,11 +1801,15 @@ struct ByteSlice sp_cp437_grid_data_ref_mut(Cp437Grid */*notnull*/ instance); * * - `cp437_grid`: instance to write to * - `value`: the value to set all cells to + * + * This function is part of the sp_cp437_grid module. */ void sp_cp437_grid_fill(Cp437Grid */*notnull*/ instance, uint8_t value); /** - *Deallocates a [Cp437Grid] instance. + *Deallocates a [`Cp437Grid`] instance. + * + * This function is part of the sp_cp437_grid module. */ void sp_cp437_grid_free(Cp437Grid */*notnull*/ instance); @@ -1705,6 +1825,8 @@ void sp_cp437_grid_free(Cp437Grid */*notnull*/ instance); * # Panics * * - when accessing `x` or `y` out of bounds + * + * This function is part of the sp_cp437_grid module. */ uint8_t sp_cp437_grid_get(Cp437Grid */*notnull*/ instance, size_t x, size_t y); @@ -1712,6 +1834,8 @@ uint8_t sp_cp437_grid_get(Cp437Grid */*notnull*/ instance, size_t x, size_t y); * Calls [`servicepoint::Cp437Grid::height`]. * * Gets the height of the grid. + * + * This function is part of the sp_cp437_grid module. */ size_t sp_cp437_grid_height(Cp437Grid */*notnull*/ instance); @@ -1761,6 +1885,8 @@ Cp437Grid */*notnull*/ sp_cp437_grid_new(size_t width, size_t height); * # Panics * * - when accessing `x` or `y` out of bounds + * + * This function is part of the sp_cp437_grid module. */ void sp_cp437_grid_set(Cp437Grid */*notnull*/ instance, size_t x, @@ -1771,16 +1897,22 @@ void sp_cp437_grid_set(Cp437Grid */*notnull*/ instance, * Calls [`servicepoint::Cp437Grid::width`]. * * Gets the width of the grid. + * + * This function is part of the sp_cp437_grid module. */ size_t sp_cp437_grid_width(Cp437Grid */*notnull*/ instance); /** - *Clones a [Packet] instance. + *Clones a [`Packet`] instance. + * + * This function is part of the sp_packet module. */ struct Packet */*notnull*/ sp_packet_clone(struct Packet */*notnull*/ instance); /** - *Deallocates a [Packet] instance. + *Deallocates a [`Packet`] instance. + * + * This function is part of the sp_packet module. */ void sp_packet_free(struct Packet */*notnull*/ instance); @@ -1793,7 +1925,9 @@ struct Packet */*notnull*/ sp_packet_from_parts(struct Header header, struct ByteSlice payload); /** - *Gets the value of field `header` of the [`servicepoint::Packet`]. + * Gets the value of field `header` of the [`servicepoint::Packet`]. + * + * This function is part of the sp_packet module. */ struct Header sp_packet_get_header(struct Packet */*notnull*/ instance); @@ -1824,7 +1958,9 @@ void sp_packet_serialize_to(struct Packet */*notnull*/ packet, struct ByteSlice buffer); /** - *Sets the value of field `header` of the [`servicepoint::Packet`]. + * Sets the value of field `header` of the [`servicepoint::Packet`]. + * + * This function is part of the sp_packet module. */ void sp_packet_set_header(struct Packet */*notnull*/ instance, struct Header value); @@ -1853,7 +1989,9 @@ bool sp_u16_to_command_code(uint16_t code, CommandCode *result); /** - *Deallocates a [UdpSocket] instance. + *Deallocates a [`UdpSocket`] instance. + * + * This function is part of the sp_udp module. */ void sp_udp_free(struct UdpSocket */*notnull*/ instance); diff --git a/src/macros.rs b/src/macros.rs index 48952db..8d4ba47 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,24 +1,22 @@ macro_rules! wrap_free { ($prefix:ident :: $typ:ty) => { - paste::paste! { - #[doc = concat!("Deallocates a [", stringify!($typ), "] instance.")] - #[no_mangle] - pub unsafe extern "C" fn [<$prefix _free>](instance: NonNull<$typ>) { + $crate::macros::wrap_functions!($prefix; + #[doc = concat!("Deallocates a [`", stringify!($typ), "`] instance.")] + fn free(instance: NonNull<$typ>) { unsafe { $crate::mem::heap_drop(instance) } } - } + ); }; } macro_rules! wrap_clone { ($prefix:ident :: $typ:ty) => { - paste::paste! { - #[doc = concat!("Clones a [", stringify!($typ), "] instance.")] - #[no_mangle] - pub unsafe extern "C" fn [<$prefix _clone>](instance: NonNull<$typ>) -> NonNull<$typ> { + $crate::macros::wrap_functions!($prefix; + #[doc = concat!("Clones a [`", stringify!($typ), "`] instance.")] + fn clone(instance: NonNull<$typ>) -> NonNull<$typ> { unsafe { $crate::mem::heap_clone(instance) } } - } + ); }; } @@ -50,33 +48,34 @@ macro_rules! wrap_methods { )+ ) => { paste::paste! { + $crate::macros::wrap_functions!($prefix; $( - #[doc = concat!(" Calls [`servicepoint::", stringify!($object_type), - "::", stringify!($function), "`].")] - #[doc = ""] - $(#[$meta])* - #[no_mangle] - pub unsafe extern "C" fn [<$prefix _ $function>]( - instance: NonNull<$object_type>, - $($param_name: $param_type),* - ) $(-> $return_type)? { - let instance = unsafe { $crate::macros:: [< nonnull_as_ $ref_or_mut >] !(instance) }; - $($( - $(let $param_let_name = $param_let_expr;)* - )?)? - #[allow( - unused_variables, - reason = "This variable may not be used depending on macro variables" )] - let result = instance.$function($($param_name),*); - $( + #[doc = concat!(" Calls [`servicepoint::", stringify!($object_type), + "::", stringify!($function), "`].")] + #[doc = ""] + $(#[$meta])* + fn $function( + instance: NonNull<$object_type>, + $($param_name: $param_type),* + ) $(-> $return_type)? { + let instance = unsafe { $crate::macros:: [< nonnull_as_ $ref_or_mut >] !(instance) }; + $($( + $(let $param_let_name = $param_let_expr;)* + )?)? + #[allow( + unused_variables, + reason = "This variable may not be used depending on macro variables" )] + let result = instance.$function($($param_name),*); $( - let $it = result; - let result = $return_expr; + $( + let $it = result; + let result = $return_expr; + )? )? - )? - return result; - } + return result; + } )+ + ); } }; } @@ -103,48 +102,48 @@ macro_rules! wrap_fields { )+ ) => { paste::paste! { - $( + $crate::macros::wrap_functions!($prefix; $( - #[doc = concat!("Gets the value of field `", stringify!($prop_name), - "` of the [`servicepoint::",stringify!($object_type),"`].")] - $($( - #[doc = ""] - #[$get_meta] - )*)? - #[no_mangle] - pub unsafe extern "C" fn [<$prefix _ get _ $prop_name>]( - instance: NonNull<$object_type> - ) -> $prop_type { - let instance = unsafe { $crate::macros::nonnull_as_ref!(instance) }; - let $prop_name = instance.$prop_name; + $( + #[doc = concat!(" Gets the value of field `", stringify!($prop_name), + "` of the [`servicepoint::",stringify!($object_type),"`].")] $($( - let $prop_name = $get_expr; - )?)? - return $prop_name; - } - )? + #[doc = ""] + #[$get_meta] + )*)? + fn []( + instance: NonNull<$object_type> + ) -> $prop_type { + let instance = unsafe { $crate::macros::nonnull_as_ref!(instance) }; + let $prop_name = instance.$prop_name; + $($( + let $prop_name = $get_expr; + )?)? + return $prop_name; + } + )? - $( - #[doc = concat!("Sets the value of field `", stringify!($prop_name), - "` of the [`servicepoint::",stringify!($object_type),"`].")] - $($( - #[doc = ""] - #[$set_meta] - )*)? - #[no_mangle] - pub unsafe extern "C" fn [<$prefix _ set _ $prop_name>]( - instance: NonNull<$object_type>, - value: $prop_type, - ) { - let instance = unsafe { $crate::macros::nonnull_as_mut!(instance) }; + $( + #[doc = concat!(" Sets the value of field `", stringify!($prop_name), + "` of the [`servicepoint::",stringify!($object_type),"`].")] $($( - let $value = value; - let value = $set_expr; - )?)? - instance.$prop_name = value; - } - )? - )+ + #[doc = ""] + #[$set_meta] + )*)? + fn []( + instance: NonNull<$object_type>, + value: $prop_type, + ) { + let instance = unsafe { $crate::macros::nonnull_as_mut!(instance) }; + $($( + let $value = value; + let value = $set_expr; + )?)? + instance.$prop_name = value; + } + )? + )+ + ); } }; }