From 8116375fd023deabf7e313eaed2d83557eb2f8ae Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Sun, 22 Jun 2025 12:16:45 +0200 Subject: [PATCH] more type name based naming --- example/Makefile | 2 +- example/src/announce.c | 28 +- example/src/brightness_tester.c | 14 +- example/src/header_logger.c | 42 +- example/src/helpers.h | 6 +- example/src/moving_line.c | 6 +- example/src/random_stuff.c | 2 +- example/src/undefined.c | 22 + example/src/wiping_clear.c | 6 +- include/servicepoint.h | 1184 +++++++++++---------- src/commands/bitmap_command.rs | 6 +- src/commands/bitvec_command.rs | 4 +- src/commands/brightness_grid_command.rs | 6 +- src/commands/cc_only_commands.rs | 24 +- src/commands/char_grid_command.rs | 4 +- src/commands/cp437_grid_command.rs | 4 +- src/commands/global_brightness_command.rs | 5 +- src/commands/mod.rs | 60 +- src/containers/bitmap.rs | 7 +- src/containers/bitvec.rs | 7 +- src/containers/brightness_grid.rs | 7 +- src/containers/byte_slice.rs | 1 + src/containers/char_grid.rs | 7 +- src/containers/cp437_grid.rs | 7 +- src/macros.rs | 65 +- src/packet.rs | 7 +- src/udp.rs | 4 +- 27 files changed, 787 insertions(+), 750 deletions(-) create mode 100644 example/src/undefined.c diff --git a/example/Makefile b/example/Makefile index 0a56e1a..15e53d1 100644 --- a/example/Makefile +++ b/example/Makefile @@ -96,7 +96,7 @@ endif # ADD NEW EXAMPLES HERE _c_src := src/announce.c src/brightness_tester.c src/header_logger.c \ - src/moving_line.c src/random_stuff.c src/wiping_clear.c + src/moving_line.c src/random_stuff.c src/wiping_clear.c src/undefined.c _programs := $(basename $(notdir $(_c_src))) _bins := $(_programs) _unstripped_bins := $(addsuffix _unstripped, $(_bins)) diff --git a/example/src/announce.c b/example/src/announce.c index bfdc48f..33da334 100644 --- a/example/src/announce.c +++ b/example/src/announce.c @@ -3,27 +3,27 @@ int main(void) { sock_init(); - sp_udp_send_header(sock, (Header) {.command_code = COMMAND_CODE_CLEAR}); + sp_udpsocket_send_header(sock, (Header) {.command_code = COMMAND_CODE_CLEAR}); - CharGrid *grid = sp_char_grid_new(5, 2); + CharGrid *grid = sp_chargrid_new(5, 2); if (grid == NULL) return 1; - sp_char_grid_set(grid, 0, 0, 'H'); - sp_char_grid_set(grid, 1, 0, 'e'); - sp_char_grid_set(grid, 2, 0, 'l'); - sp_char_grid_set(grid, 3, 0, 'l'); - sp_char_grid_set(grid, 4, 0, 'o'); - sp_char_grid_set(grid, 0, 1, 'W'); - sp_char_grid_set(grid, 1, 1, 'o'); - sp_char_grid_set(grid, 2, 1, 'r'); - sp_char_grid_set(grid, 3, 1, 'l'); - sp_char_grid_set(grid, 4, 1, 'd'); + sp_chargrid_set(grid, 0, 0, 'H'); + sp_chargrid_set(grid, 1, 0, 'e'); + sp_chargrid_set(grid, 2, 0, 'l'); + sp_chargrid_set(grid, 3, 0, 'l'); + sp_chargrid_set(grid, 4, 0, 'o'); + sp_chargrid_set(grid, 0, 1, 'W'); + sp_chargrid_set(grid, 1, 1, 'o'); + sp_chargrid_set(grid, 2, 1, 'r'); + sp_chargrid_set(grid, 3, 1, 'l'); + sp_chargrid_set(grid, 4, 1, 'd'); - Packet *packet = sp_char_grid_into_packet(grid, 0, 0); + Packet *packet = sp_chargrid_into_packet(grid, 0, 0); if (packet == NULL) return 1; - sp_udp_send_packet(sock, packet); + sp_udpsocket_send_packet(sock, packet); return 0; } diff --git a/example/src/brightness_tester.c b/example/src/brightness_tester.c index 2257162..9d17dc7 100644 --- a/example/src/brightness_tester.c +++ b/example/src/brightness_tester.c @@ -5,14 +5,14 @@ void enable_all_pixels(void) { Bitmap *all_on = sp_bitmap_new_max_sized(); sp_bitmap_fill(all_on, true); - BitmapCommand *bitmapCommand = sp_cmd_bitmap_from_bitmap(all_on); - Packet *packet = sp_cmd_bitmap_try_into_packet(bitmapCommand); + BitmapCommand *bitmapCommand = sp_bitmapcommand_from_bitmap(all_on); + Packet *packet = sp_bitmapcommand_try_into_packet(bitmapCommand); if (packet != NULL) - sp_udp_send_packet(sock, packet); + sp_udpsocket_send_packet(sock, packet); } void make_brightness_pattern(BrightnessGrid *grid) { - ByteSlice slice = sp_brightness_grid_data_ref_mut(grid); + ByteSlice slice = sp_brightnessgrid_data_ref_mut(grid); for (size_t index = 0; index < slice.length; index++) { slice.start[index] = (uint8_t)(index % ((size_t) Brightness_MAX)); } @@ -23,13 +23,13 @@ int main(void) { enable_all_pixels(); - BrightnessGrid *grid = sp_brightness_grid_new(TILE_WIDTH, TILE_HEIGHT); + BrightnessGrid *grid = sp_brightnessgrid_new(TILE_WIDTH, TILE_HEIGHT); make_brightness_pattern(grid); - Packet *packet = sp_cmd_brightness_grid_into_packet(sp_cmd_brightness_grid_from_grid(grid)); + Packet *packet = sp_brightnessgridcommand_into_packet(sp_brightnessgridcommand_from_grid(grid)); if (packet == NULL) return -2; - sp_udp_send_packet(sock, packet); + sp_udpsocket_send_packet(sock, packet); return 0; } diff --git a/example/src/header_logger.c b/example/src/header_logger.c index 5f04ac4..ec421dd 100644 --- a/example/src/header_logger.c +++ b/example/src/header_logger.c @@ -28,12 +28,12 @@ bool log_command(struct Command command) { case COMMAND_TAG_BITMAP: { BitmapCommand *bitmapCommand = command.data.bitmap; - CompressionCode compression = sp_cmd_bitmap_get_compression(bitmapCommand); + CompressionCode compression = sp_bitmapcommand_get_compression(bitmapCommand); size_t x, y; - sp_cmd_bitmap_get_origin(bitmapCommand, &x, &y); + sp_bitmapcommand_get_origin(bitmapCommand, &x, &y); - Bitmap *bitmap = sp_cmd_bitmap_get_bitmap_mut(bitmapCommand); + Bitmap *bitmap = sp_bitmapcommand_get_bitmap_mut(bitmapCommand); size_t w = sp_bitmap_width(bitmap); size_t h = sp_bitmap_height(bitmap); @@ -45,11 +45,11 @@ bool log_command(struct Command command) { BrightnessGridCommand *gridCommand = command.data.brightness_grid; size_t x, y; - sp_cmd_brightness_grid_get_origin(gridCommand, &x, &y); + sp_brightnessgridcommand_get_origin(gridCommand, &x, &y); - BrightnessGrid *grid = sp_cmd_brightness_grid_get_grid_mut(gridCommand); - size_t w = sp_brightness_grid_width(grid); - size_t h = sp_brightness_grid_height(grid); + BrightnessGrid *grid = sp_brightnessgridcommand_get_grid_mut(gridCommand); + size_t w = sp_brightnessgrid_width(grid); + size_t h = sp_brightnessgrid_height(grid); printf("-> BrightnessGridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n", x, y, w, h); @@ -59,11 +59,11 @@ bool log_command(struct Command command) { CharGridCommand *gridCommand = command.data.char_grid; size_t x, y; - sp_cmd_char_grid_get_origin(gridCommand, &x, &y); + sp_chargridcommand_get_origin(gridCommand, &x, &y); - CharGrid *grid = sp_cmd_char_grid_get_grid_mut(gridCommand); - size_t w = sp_char_grid_width(grid); - size_t h = sp_char_grid_height(grid); + CharGrid *grid = sp_chargridcommand_get_grid_mut(gridCommand); + size_t w = sp_chargrid_width(grid); + size_t h = sp_chargrid_height(grid); printf("-> CharGridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n", x, y, w, h); @@ -73,11 +73,11 @@ bool log_command(struct Command command) { Cp437GridCommand *gridCommand = command.data.cp437_grid; size_t x, y; - sp_cmd_cp437_grid_get_origin(gridCommand, &x, &y); + sp_cp437gridcommand_get_origin(gridCommand, &x, &y); - Cp437Grid *grid = sp_cmd_cp437_grid_get_grid_mut(gridCommand); - size_t w = sp_cp437_grid_width(grid); - size_t h = sp_cp437_grid_height(grid); + Cp437Grid *grid = sp_cp437gridcommand_get_grid_mut(gridCommand); + size_t w = sp_cp437grid_width(grid); + size_t h = sp_cp437grid_height(grid); printf("-> Cp437GridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n", x, y, w, h); @@ -86,10 +86,10 @@ bool log_command(struct Command command) { case COMMAND_TAG_BIT_VEC: { BitVecCommand *bitvecCommand = command.data.bit_vec; - size_t offset = sp_cmd_bitvec_get_offset(bitvecCommand); - CompressionCode compression = sp_cmd_bitvec_get_compression(bitvecCommand); + size_t offset = sp_bitveccommand_get_offset(bitvecCommand); + CompressionCode compression = sp_bitveccommand_get_compression(bitvecCommand); - BinaryOperation operation = sp_cmd_bitvec_get_operation(bitvecCommand); + BinaryOperation operation = sp_bitveccommand_get_operation(bitvecCommand); char *operationText; switch (operation) { case BINARY_OPERATION_AND: @@ -109,8 +109,8 @@ bool log_command(struct Command command) { break; } - BitVec *bitvec = sp_cmd_bitvec_get_bitvec_mut(bitvecCommand); - size_t len = sp_bitvec_len(bitvec); + BitVec *bitvec = sp_bitveccommand_get_bitvec_mut(bitvecCommand); + size_t len = sp_displaybitvec_len(bitvec); printf("-> BitVecCommand with params: offset=%zu, length=%zu, compression=%hu, operation=%s\n", offset, len, compression, operationText); @@ -129,7 +129,7 @@ bool log_command(struct Command command) { break; } case COMMAND_TAG_GLOBAL_BRIGHTNESS: { - Brightness brightness = sp_cmd_brightness_global_get_brightness(command.data.global_brightness); + Brightness brightness = sp_globalbrightnesscommand_get_brightness(command.data.global_brightness); printf("-> GlobalBrightnessCommand with params: brightness=%hu\n", brightness); break; } diff --git a/example/src/helpers.h b/example/src/helpers.h index bc6c119..ee415f2 100644 --- a/example/src/helpers.h +++ b/example/src/helpers.h @@ -10,12 +10,12 @@ static UdpSocket *sock = NULL; void sock_free() { - sp_udp_free(sock); + sp_udpsocket_free(sock); } void sock_init() { - //sock = sp_udp_open_ipv4(127, 0, 0, 1, 2342); - sock = sp_udp_open_ipv4(172, 23, 42, 29, 2342); + sock = sp_udpsocket_open_ipv4(127, 0, 0, 1, 2342); + //sock = sp_udp_open_ipv4(172, 23, 42, 29, 2342); if (sock == NULL) exit(-1); atexit(sock_free); diff --git a/example/src/moving_line.c b/example/src/moving_line.c index 35ba20d..12a1a9b 100644 --- a/example/src/moving_line.c +++ b/example/src/moving_line.c @@ -13,14 +13,14 @@ int main(void) { sp_bitmap_set(bitmap, (y + x) % PIXEL_WIDTH, y, true); } - BitmapCommand *command = sp_cmd_bitmap_from_bitmap(sp_bitmap_clone(bitmap)); - Packet *packet = sp_cmd_bitmap_try_into_packet(command); + BitmapCommand *command = sp_bitmapcommand_from_bitmap(sp_bitmap_clone(bitmap)); + Packet *packet = sp_bitmapcommand_try_into_packet(command); if (packet == NULL) { result = -2; goto exit; } - if (!sp_udp_send_packet(sock, packet)) { + if (!sp_udpsocket_send_packet(sock, packet)) { result = -3; goto exit; } diff --git a/example/src/random_stuff.c b/example/src/random_stuff.c index b55e42c..8838123 100644 --- a/example/src/random_stuff.c +++ b/example/src/random_stuff.c @@ -18,6 +18,6 @@ int main(void) { Header *header = sp_packet_get_header_mut(packet); printf("[%d, %d, %d, %d, %d]\n", header->command_code, header->a, header->b, header->c, header->d); - sp_udp_send_packet(sock, packet); + sp_udpsocket_send_packet(sock, packet); return 0; } diff --git a/example/src/undefined.c b/example/src/undefined.c new file mode 100644 index 0000000..44aaf6d --- /dev/null +++ b/example/src/undefined.c @@ -0,0 +1,22 @@ +#include +#include "servicepoint.h" +#include "helpers.h" + +/// DO NOT DO ANY OF THIS! +int main(void) { + BitmapCommand *bmcmd = sp_bitmapcommand_new(sp_bitmap_new_max_sized(), 0, 0, COMPRESSION_CODE_UNCOMPRESSED); + BitVecCommand *bvcmd = (BitVecCommand *) bmcmd; + sp_bitveccommand_free(bvcmd); + + uint8_t *data = calloc(1024, 1); + struct Command generic = { + .tag = COMMAND_TAG_BRIGHTNESS_GRID, + .data = {.null = data}, + }; + + sock_init(); + + sp_udpsocket_send_command(sock, generic); + + return 0; +} diff --git a/example/src/wiping_clear.c b/example/src/wiping_clear.c index a3f7017..3984169 100644 --- a/example/src/wiping_clear.c +++ b/example/src/wiping_clear.c @@ -14,13 +14,13 @@ int main() { } BitVec *bitvec = sp_bitmap_into_bitvec(sp_bitmap_clone(enabled_pixels)); - BitVecCommand *command = sp_cmd_bitvec_new(bitvec, 0, BINARY_OPERATION_AND, COMPRESSION_CODE_LZMA); - Packet *packet = sp_cmd_bitvec_try_into_packet(command); + BitVecCommand *command = sp_bitveccommand_new(bitvec, 0, BINARY_OPERATION_AND, COMPRESSION_CODE_LZMA); + Packet *packet = sp_bitveccommand_try_into_packet(command); if (packet == NULL) { result = -2; goto exit; } - if (!sp_udp_send_packet(sock, packet)) { + if (!sp_udpsocket_send_packet(sock, packet)) { result = -3; goto exit; } diff --git a/include/servicepoint.h b/include/servicepoint.h index 0c6490f..e0e6cc4 100644 --- a/include/servicepoint.h +++ b/include/servicepoint.h @@ -476,6 +476,11 @@ typedef struct ByteSlice { size_t length; } ByteSlice; +/** + * Type alias for documenting the meaning of the u16 in enum values + */ +typedef size_t Offset; + /** * A grid containing brightness values. * @@ -542,11 +547,6 @@ typedef uint8_t Brightness; */ typedef struct ValueGrid_char CharGrid; -/** - * Type alias for documenting the meaning of the u16 in enum values - */ -typedef size_t Offset; - /** * A grid containing codepage 437 characters. * @@ -816,62 +816,103 @@ void sp_bitmap_set(struct Bitmap */*notnull*/ instance, size_t sp_bitmap_width(struct Bitmap */*notnull*/ instance); /** - * Calls method [`servicepoint::DisplayBitVec::as_raw_mut_slice`]. + *Clones a [`BitmapCommand`] 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 `bitvec` module. + * This function is part of the `bitmapcommand` module. */ -struct ByteSlice sp_bitvec_as_raw_mut_slice(BitVec */*notnull*/ instance); +struct BitmapCommand */*notnull*/ sp_bitmapcommand_clone(struct BitmapCommand */*notnull*/ instance); /** - *Clones a [`DisplayBitVec`] instance. + *Deallocates a [`BitmapCommand`] instance. * - * This function is part of the `bitvec` module. + * This function is part of the `bitmapcommand` module. */ -BitVec */*notnull*/ sp_bitvec_clone(BitVec */*notnull*/ instance); +void sp_bitmapcommand_free(struct BitmapCommand */*notnull*/ instance); /** - * Calls method [`servicepoint::DisplayBitVec::fill`]. + * Move the provided [Bitmap] into a new [BitmapCommand], + * leaving other fields as their default values. * - * Sets the value of all bits. + * Rust equivalent: `BitmapCommand::from(bitmap)` * - * # Arguments - * - * - `value`: the value to set all bits to - * - * This function is part of the `bitvec` module. + * This function is part of the `bitmapcommand` module. */ -void sp_bitvec_fill(BitVec */*notnull*/ instance, bool value); +struct BitmapCommand */*notnull*/ sp_bitmapcommand_from_bitmap(struct Bitmap */*notnull*/ bitmap); /** - *Deallocates a [`DisplayBitVec`] instance. + * Gets a reference to the field `bitmap` of the [`servicepoint::BitmapCommand`]. * - * This function is part of the `bitvec` module. + * - The returned reference inherits the lifetime of object in which it is contained. + * - The returned pointer may not be used in a function that consumes the instance, e.g. to create a command. + * + * This function is part of the `bitmapcommand` module. */ -void sp_bitvec_free(BitVec */*notnull*/ instance); +struct Bitmap */*notnull*/ sp_bitmapcommand_get_bitmap_mut(struct BitmapCommand */*notnull*/ instance); /** - * Calls method [`servicepoint::DisplayBitVec::get`]. + * Gets the value of field `compression` of the [`servicepoint::BitmapCommand`]. * - * Gets the value of a bit. - * - * # Arguments - * - * - `bit_vec`: instance to read from - * - `index`: the bit index to read - * - * returns: value of the bit - * - * # Panics - * - * - when accessing `index` out of bounds - * - * This function is part of the `bitvec` module. + * This function is part of the `bitmapcommand` module. */ -bool sp_bitvec_get(BitVec */*notnull*/ instance, size_t index); +CompressionCode sp_bitmapcommand_get_compression(struct BitmapCommand */*notnull*/ instance); + +/** + * Reads the origin field of the [`BitmapCommand`]. + * + * This function is part of the `bitmapcommand` module. + */ +void sp_bitmapcommand_get_origin(struct BitmapCommand */*notnull*/ command, + size_t */*notnull*/ origin_x, + size_t */*notnull*/ origin_y); + +/** + * Sets a window of pixels to the specified values. + * + * The passed [Bitmap] gets consumed. + * + * Returns: a new [BitmapCommand] instance. + * + * This function is part of the `bitmapcommand` module. + */ +struct BitmapCommand */*notnull*/ sp_bitmapcommand_new(struct Bitmap */*notnull*/ bitmap, + size_t origin_x, + size_t origin_y, + CompressionCode compression); + +/** + * Sets the value of field `bitmap` of the [`servicepoint::BitmapCommand`]. + * The provided value is moved into the instance, potentially invalidating previously taken references. + * + * This function is part of the `bitmapcommand` module. + */ +void sp_bitmapcommand_set_bitmap(struct BitmapCommand */*notnull*/ instance, + struct Bitmap */*notnull*/ value); + +/** + * Sets the value of field `compression` of the [`servicepoint::BitmapCommand`]. + * + * This function is part of the `bitmapcommand` module. + */ +void sp_bitmapcommand_set_compression(struct BitmapCommand */*notnull*/ instance, + CompressionCode value); + +/** + * Overwrites the origin field of the [`BitmapCommand`]. + * + * This function is part of the `bitmapcommand` module. + */ +void sp_bitmapcommand_set_origin(struct BitmapCommand */*notnull*/ command, + size_t origin_x, + size_t origin_y); + +/** + * Tries to turn a [BitmapCommand] into a [Packet]. + * + * Returns: NULL or a [Packet] containing the command. + * + * This function is part of the `bitmapcommand` module. + */ +struct Packet *sp_bitmapcommand_try_into_packet(struct BitmapCommand */*notnull*/ command); /** * Creates a [BitVecCommand] and immediately turns that into a [Packet]. @@ -887,24 +928,6 @@ struct Packet *sp_bitvec_into_packet(BitVec */*notnull*/ bitvec, BinaryOperation operation, CompressionCode compression); -/** - * Calls method [`servicepoint::DisplayBitVec::is_empty`]. - * - * Returns true if length is 0. - * - * This function is part of the `bitvec` module. - */ -bool sp_bitvec_is_empty(BitVec */*notnull*/ instance); - -/** - * Calls method [`servicepoint::DisplayBitVec::len`]. - * - * Gets the length in bits. - * - * This function is part of the `bitvec` module. - */ -size_t sp_bitvec_len(BitVec */*notnull*/ instance); - /** * Interpret the data as a series of bits and load then into a new [DisplayBitVec] instance. * @@ -932,22 +955,112 @@ BitVec */*notnull*/ sp_bitvec_load(struct ByteSlice data); BitVec */*notnull*/ sp_bitvec_new(size_t size); /** - * Calls method [`servicepoint::DisplayBitVec::set`]. + *Clones a [`BitVecCommand`] instance. * - * Sets the value of a bit. - * - * # Arguments - * - * - `index`: the bit index to edit - * - `value`: the value to set the bit to - * - * # Panics - * - * - when accessing `index` out of bounds - * - * This function is part of the `bitvec` module. + * This function is part of the `bitveccommand` module. */ -void sp_bitvec_set(BitVec */*notnull*/ instance, size_t index, bool value); +struct BitVecCommand */*notnull*/ sp_bitveccommand_clone(struct BitVecCommand */*notnull*/ instance); + +/** + *Deallocates a [`BitVecCommand`] instance. + * + * This function is part of the `bitveccommand` module. + */ +void sp_bitveccommand_free(struct BitVecCommand */*notnull*/ instance); + +/** + * Gets a reference to the field `bitvec` of the [`servicepoint::BitVecCommand`]. + * + * - The returned reference inherits the lifetime of object in which it is contained. + * - The returned pointer may not be used in a function that consumes the instance, e.g. to create a command. + * + * This function is part of the `bitveccommand` module. + */ +BitVec */*notnull*/ sp_bitveccommand_get_bitvec_mut(struct BitVecCommand */*notnull*/ instance); + +/** + * Gets the value of field `compression` of the [`servicepoint::BitVecCommand`]. + * + * This function is part of the `bitveccommand` module. + */ +CompressionCode sp_bitveccommand_get_compression(struct BitVecCommand */*notnull*/ instance); + +/** + * Gets the value of field `offset` of the [`servicepoint::BitVecCommand`]. + * + * This function is part of the `bitveccommand` module. + */ +Offset sp_bitveccommand_get_offset(struct BitVecCommand */*notnull*/ instance); + +/** + * Gets the value of field `operation` of the [`servicepoint::BitVecCommand`]. + * + * This function is part of the `bitveccommand` module. + */ +BinaryOperation sp_bitveccommand_get_operation(struct BitVecCommand */*notnull*/ instance); + +/** + * Set pixel data starting at the pixel offset on screen. + * + * The screen will continuously overwrite more pixel data without regarding the offset, meaning + * once the starting row is full, overwriting will continue on column 0. + * + * The [`BinaryOperation`] will be applied on the display comparing old and sent bit. + * + * `new_bit = old_bit op sent_bit` + * + * For example, [`BinaryOperation::Or`] can be used to turn on some pixels without affecting other pixels. + * + * The contained [`DisplayBitVec`] is always uncompressed. + * + * This function is part of the `bitveccommand` module. + */ +struct BitVecCommand */*notnull*/ sp_bitveccommand_new(BitVec */*notnull*/ bitvec, + size_t offset, + BinaryOperation operation, + CompressionCode compression); + +/** + * Sets the value of field `bitvec` of the [`servicepoint::BitVecCommand`]. + * The provided value is moved into the instance, potentially invalidating previously taken references. + * + * This function is part of the `bitveccommand` module. + */ +void sp_bitveccommand_set_bitvec(struct BitVecCommand */*notnull*/ instance, + BitVec */*notnull*/ value); + +/** + * Sets the value of field `compression` of the [`servicepoint::BitVecCommand`]. + * + * This function is part of the `bitveccommand` module. + */ +void sp_bitveccommand_set_compression(struct BitVecCommand */*notnull*/ instance, + CompressionCode value); + +/** + * Sets the value of field `offset` of the [`servicepoint::BitVecCommand`]. + * + * This function is part of the `bitveccommand` module. + */ +void sp_bitveccommand_set_offset(struct BitVecCommand */*notnull*/ instance, + Offset value); + +/** + * Sets the value of field `operation` of the [`servicepoint::BitVecCommand`]. + * + * This function is part of the `bitveccommand` module. + */ +void sp_bitveccommand_set_operation(struct BitVecCommand */*notnull*/ instance, + BinaryOperation value); + +/** + * Tries to turn a [BitVecCommand] into a [Packet]. + * + * Returns: NULL or a [Packet] containing the command. + * + * This function is part of the `bitveccommand` module. + */ +struct Packet *sp_bitveccommand_try_into_packet(struct BitVecCommand */*notnull*/ command); /** *Clones a [`BrightnessGrid`] instance. @@ -1098,6 +1211,87 @@ void sp_brightnessgrid_set(BrightnessGrid */*notnull*/ instance, */ size_t sp_brightnessgrid_width(BrightnessGrid */*notnull*/ instance); +/** + *Clones a [`BrightnessGridCommand`] instance. + * + * This function is part of the `brightnessgridcommand` module. + */ +struct BrightnessGridCommand */*notnull*/ sp_brightnessgridcommand_clone(struct BrightnessGridCommand */*notnull*/ instance); + +/** + *Deallocates a [`BrightnessGridCommand`] instance. + * + * This function is part of the `brightnessgridcommand` module. + */ +void sp_brightnessgridcommand_free(struct BrightnessGridCommand */*notnull*/ instance); + +/** + * Moves the provided [BrightnessGrid] into a new [BrightnessGridCommand], + * leaving other fields as their default values. + * + * This function is part of the `brightnessgridcommand` module. + */ +struct BrightnessGridCommand */*notnull*/ sp_brightnessgridcommand_from_grid(BrightnessGrid */*notnull*/ grid); + +/** + * Gets a reference to the field `grid` of the [`servicepoint::BrightnessGridCommand`]. + * + * - The returned reference inherits the lifetime of object in which it is contained. + * - The returned pointer may not be used in a function that consumes the instance, e.g. to create a command. + * + * This function is part of the `brightnessgridcommand` module. + */ +BrightnessGrid */*notnull*/ sp_brightnessgridcommand_get_grid_mut(struct BrightnessGridCommand */*notnull*/ instance); + +/** + * Reads the origin field of the [`BrightnessGridCommand`]. + * + * This function is part of the `brightnessgridcommand` module. + */ +void sp_brightnessgridcommand_get_origin(struct BrightnessGridCommand */*notnull*/ command, + size_t */*notnull*/ origin_x, + size_t */*notnull*/ origin_y); + +/** + * Tries to turn a [BrightnessGridCommand] into a [Packet]. + * + * Returns: NULL or a [Packet] containing the command. + * + * This function is part of the `brightnessgridcommand` module. + */ +struct Packet *sp_brightnessgridcommand_into_packet(struct BrightnessGridCommand */*notnull*/ command); + +/** + * Set the brightness of individual tiles in a rectangular area of the display. + * + * The passed [BrightnessGrid] gets consumed. + * + * Returns: a new [BrightnessGridCommand] instance. + * + * This function is part of the `brightnessgridcommand` module. + */ +struct BrightnessGridCommand */*notnull*/ sp_brightnessgridcommand_new(BrightnessGrid */*notnull*/ grid, + size_t origin_x, + size_t origin_y); + +/** + * Sets the value of field `grid` of the [`servicepoint::BrightnessGridCommand`]. + * The provided value is moved into the instance, potentially invalidating previously taken references. + * + * This function is part of the `brightnessgridcommand` module. + */ +void sp_brightnessgridcommand_set_grid(struct BrightnessGridCommand */*notnull*/ instance, + BrightnessGrid */*notnull*/ value); + +/** + * Overwrites the origin field of the [`BrightnessGridCommand`]. + * + * This function is part of the `brightnessgridcommand` module. + */ +void sp_brightnessgridcommand_set_origin(struct BrightnessGridCommand */*notnull*/ command, + size_t origin_x, + size_t origin_y); + /** *Clones a [`CharGrid`] instance. * @@ -1225,307 +1419,81 @@ void sp_chargrid_set(CharGrid */*notnull*/ instance, */ size_t sp_chargrid_width(CharGrid */*notnull*/ instance); -/** - *Clones a [`BitmapCommand`] instance. - * - * This function is part of the `cmd_bitmap` module. - */ -struct BitmapCommand */*notnull*/ sp_cmd_bitmap_clone(struct BitmapCommand */*notnull*/ instance); - -/** - *Deallocates a [`BitmapCommand`] instance. - * - * This function is part of the `cmd_bitmap` module. - */ -void sp_cmd_bitmap_free(struct BitmapCommand */*notnull*/ instance); - -/** - * Move the provided [Bitmap] into a new [BitmapCommand], - * leaving other fields as their default values. - * - * Rust equivalent: `BitmapCommand::from(bitmap)` - * - * This function is part of the `cmd_bitmap` module. - */ -struct BitmapCommand */*notnull*/ sp_cmd_bitmap_from_bitmap(struct Bitmap */*notnull*/ bitmap); - -/** - * Gets a reference to the field `bitmap` of the [`servicepoint::BitmapCommand`]. - * - * - The returned reference inherits the lifetime of object in which it is contained. - * - The returned pointer may not be used in a function that consumes the instance, e.g. to create a command. - * - * This function is part of the `cmd_bitmap` module. - */ -struct Bitmap */*notnull*/ sp_cmd_bitmap_get_bitmap_mut(struct BitmapCommand */*notnull*/ instance); - -/** - * Gets the value of field `compression` of the [`servicepoint::BitmapCommand`]. - * - * This function is part of the `cmd_bitmap` module. - */ -CompressionCode sp_cmd_bitmap_get_compression(struct BitmapCommand */*notnull*/ instance); - -/** - * Reads the origin field of the [`BitmapCommand`]. - * - * This function is part of the `cmd_bitmap` module. - */ -void sp_cmd_bitmap_get_origin(struct BitmapCommand */*notnull*/ command, - size_t */*notnull*/ origin_x, - size_t */*notnull*/ origin_y); - -/** - * Sets a window of pixels to the specified values. - * - * The passed [Bitmap] gets consumed. - * - * Returns: a new [BitmapCommand] instance. - * - * This function is part of the `cmd_bitmap` module. - */ -struct BitmapCommand */*notnull*/ sp_cmd_bitmap_new(struct Bitmap */*notnull*/ bitmap, - size_t origin_x, - size_t origin_y, - CompressionCode compression); - -/** - * Sets the value of field `bitmap` of the [`servicepoint::BitmapCommand`]. - * The provided value is moved into the instance, potentially invalidating previously taken references. - * - * This function is part of the `cmd_bitmap` module. - */ -void sp_cmd_bitmap_set_bitmap(struct BitmapCommand */*notnull*/ instance, - struct Bitmap */*notnull*/ value); - -/** - * Sets the value of field `compression` of the [`servicepoint::BitmapCommand`]. - * - * This function is part of the `cmd_bitmap` module. - */ -void sp_cmd_bitmap_set_compression(struct BitmapCommand */*notnull*/ instance, - CompressionCode value); - -/** - * Overwrites the origin field of the [`BitmapCommand`]. - * - * This function is part of the `cmd_bitmap` module. - */ -void sp_cmd_bitmap_set_origin(struct BitmapCommand */*notnull*/ command, - size_t origin_x, - size_t origin_y); - -/** - * Tries to turn a [BitmapCommand] into a [Packet]. - * - * Returns: NULL or a [Packet] containing the command. - * - * This function is part of the `cmd_bitmap` module. - */ -struct Packet *sp_cmd_bitmap_try_into_packet(struct BitmapCommand */*notnull*/ command); - -/** - *Clones a [`BitVecCommand`] instance. - * - * This function is part of the `cmd_bitvec` module. - */ -struct BitVecCommand */*notnull*/ sp_cmd_bitvec_clone(struct BitVecCommand */*notnull*/ instance); - -/** - *Deallocates a [`BitVecCommand`] instance. - * - * This function is part of the `cmd_bitvec` module. - */ -void sp_cmd_bitvec_free(struct BitVecCommand */*notnull*/ instance); - -/** - * Gets a reference to the field `bitvec` of the [`servicepoint::BitVecCommand`]. - * - * - The returned reference inherits the lifetime of object in which it is contained. - * - The returned pointer may not be used in a function that consumes the instance, e.g. to create a command. - * - * This function is part of the `cmd_bitvec` module. - */ -BitVec */*notnull*/ sp_cmd_bitvec_get_bitvec_mut(struct BitVecCommand */*notnull*/ instance); - -/** - * Gets the value of field `compression` of the [`servicepoint::BitVecCommand`]. - * - * This function is part of the `cmd_bitvec` module. - */ -CompressionCode sp_cmd_bitvec_get_compression(struct BitVecCommand */*notnull*/ instance); - -/** - * Gets the value of field `offset` of the [`servicepoint::BitVecCommand`]. - * - * This function is part of the `cmd_bitvec` module. - */ -Offset sp_cmd_bitvec_get_offset(struct BitVecCommand */*notnull*/ instance); - -/** - * Gets the value of field `operation` of the [`servicepoint::BitVecCommand`]. - * - * This function is part of the `cmd_bitvec` module. - */ -BinaryOperation sp_cmd_bitvec_get_operation(struct BitVecCommand */*notnull*/ instance); - -/** - * Set pixel data starting at the pixel offset on screen. - * - * The screen will continuously overwrite more pixel data without regarding the offset, meaning - * once the starting row is full, overwriting will continue on column 0. - * - * The [`BinaryOperation`] will be applied on the display comparing old and sent bit. - * - * `new_bit = old_bit op sent_bit` - * - * For example, [`BinaryOperation::Or`] can be used to turn on some pixels without affecting other pixels. - * - * The contained [`DisplayBitVec`] is always uncompressed. - * - * This function is part of the `cmd_bitvec` module. - */ -struct BitVecCommand */*notnull*/ sp_cmd_bitvec_new(BitVec */*notnull*/ bitvec, - size_t offset, - BinaryOperation operation, - CompressionCode compression); - -/** - * Sets the value of field `bitvec` of the [`servicepoint::BitVecCommand`]. - * The provided value is moved into the instance, potentially invalidating previously taken references. - * - * This function is part of the `cmd_bitvec` module. - */ -void sp_cmd_bitvec_set_bitvec(struct BitVecCommand */*notnull*/ instance, - BitVec */*notnull*/ value); - -/** - * Sets the value of field `compression` of the [`servicepoint::BitVecCommand`]. - * - * This function is part of the `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`]. - * - * This function is part of the `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`]. - * - * This function is part of the `cmd_bitvec` module. - */ -void sp_cmd_bitvec_set_operation(struct BitVecCommand */*notnull*/ instance, - BinaryOperation value); - -/** - * Tries to turn a [BitVecCommand] into a [Packet]. - * - * Returns: NULL or a [Packet] containing the command. - * - * This function is part of the `cmd_bitvec` module. - */ -struct Packet *sp_cmd_bitvec_try_into_packet(struct BitVecCommand */*notnull*/ command); - -/** - *Clones a [`BrightnessGridCommand`] instance. - * - * This function is part of the `cmd_brightnessgrid` module. - */ -struct BrightnessGridCommand */*notnull*/ sp_cmd_brightnessgrid_clone(struct BrightnessGridCommand */*notnull*/ instance); - -/** - *Deallocates a [`BrightnessGridCommand`] instance. - * - * This function is part of the `cmd_brightnessgrid` module. - */ -void sp_cmd_brightnessgrid_free(struct BrightnessGridCommand */*notnull*/ instance); - -/** - * Moves the provided [BrightnessGrid] into a new [BrightnessGridCommand], - * leaving other fields as their default values. - * - * This function is part of the `cmd_brightnessgrid` module. - */ -struct BrightnessGridCommand */*notnull*/ sp_cmd_brightnessgrid_from_grid(BrightnessGrid */*notnull*/ grid); - -/** - * Gets a reference to the field `grid` of the [`servicepoint::BrightnessGridCommand`]. - * - * - The returned reference inherits the lifetime of object in which it is contained. - * - The returned pointer may not be used in a function that consumes the instance, e.g. to create a command. - * - * This function is part of the `cmd_brightnessgrid` module. - */ -BrightnessGrid */*notnull*/ sp_cmd_brightnessgrid_get_grid_mut(struct BrightnessGridCommand */*notnull*/ instance); - -/** - * Reads the origin field of the [`BrightnessGridCommand`]. - * - * This function is part of the `cmd_brightnessgrid` module. - */ -void sp_cmd_brightnessgrid_get_origin(struct BrightnessGridCommand */*notnull*/ command, - size_t */*notnull*/ origin_x, - size_t */*notnull*/ origin_y); - -/** - * Tries to turn a [BrightnessGridCommand] into a [Packet]. - * - * Returns: NULL or a [Packet] containing the command. - * - * This function is part of the `cmd_brightnessgrid` module. - */ -struct Packet *sp_cmd_brightnessgrid_into_packet(struct BrightnessGridCommand */*notnull*/ command); - -/** - * Set the brightness of individual tiles in a rectangular area of the display. - * - * The passed [BrightnessGrid] gets consumed. - * - * Returns: a new [BrightnessGridCommand] instance. - * - * This function is part of the `cmd_brightnessgrid` module. - */ -struct BrightnessGridCommand */*notnull*/ sp_cmd_brightnessgrid_new(BrightnessGrid */*notnull*/ grid, - size_t origin_x, - size_t origin_y); - -/** - * Sets the value of field `grid` of the [`servicepoint::BrightnessGridCommand`]. - * The provided value is moved into the instance, potentially invalidating previously taken references. - * - * This function is part of the `cmd_brightnessgrid` module. - */ -void sp_cmd_brightnessgrid_set_grid(struct BrightnessGridCommand */*notnull*/ instance, - BrightnessGrid */*notnull*/ value); - -/** - * Overwrites the origin field of the [`BrightnessGridCommand`]. - * - * This function is part of the `cmd_brightnessgrid` module. - */ -void sp_cmd_brightnessgrid_set_origin(struct BrightnessGridCommand */*notnull*/ command, - size_t origin_x, - size_t origin_y); - /** *Clones a [`CharGridCommand`] instance. * - * This function is part of the `cmd_chargrid` module. + * This function is part of the `chargridcommand` module. */ -struct CharGridCommand */*notnull*/ sp_cmd_chargrid_clone(struct CharGridCommand */*notnull*/ instance); +struct CharGridCommand */*notnull*/ sp_chargridcommand_clone(struct CharGridCommand */*notnull*/ instance); /** *Deallocates a [`CharGridCommand`] instance. * - * This function is part of the `cmd_chargrid` module. + * This function is part of the `chargridcommand` module. */ -void sp_cmd_chargrid_free(struct CharGridCommand */*notnull*/ instance); +void sp_chargridcommand_free(struct CharGridCommand */*notnull*/ instance); + +/** + * Gets a reference to the field `grid` of the [`servicepoint::CharGridCommand`]. + * + * - The returned reference inherits the lifetime of object in which it is contained. + * - The returned pointer may not be used in a function that consumes the instance, e.g. to create a command. + * + * This function is part of the `chargridcommand` module. + */ +CharGrid */*notnull*/ sp_chargridcommand_get_grid_mut(struct CharGridCommand */*notnull*/ instance); + +/** + * Reads the origin field of the [`CharGridCommand`]. + * + * This function is part of the `chargridcommand` module. + */ +void sp_chargridcommand_get_origin(struct CharGridCommand */*notnull*/ command, + size_t */*notnull*/ origin_x, + size_t */*notnull*/ origin_y); + +/** + * Sets the value of field `grid` of the [`servicepoint::CharGridCommand`]. + * The provided value is moved into the instance, potentially invalidating previously taken references. + * + * This function is part of the `chargridcommand` module. + */ +void sp_chargridcommand_set_grid(struct CharGridCommand */*notnull*/ instance, + CharGrid */*notnull*/ value); + +/** + * Overwrites the origin field of the [`CharGridCommand`]. + * + * This function is part of the `chargridcommand` module. + */ +void sp_chargridcommand_set_origin(struct CharGridCommand */*notnull*/ command, + size_t origin_x, + size_t origin_y); + +/** + *Clones a [`ClearCommand`] instance. + * + * This function is part of the `clearcommand` module. + */ +struct ClearCommand */*notnull*/ sp_clearcommand_clone(struct ClearCommand */*notnull*/ instance); + +/** + *Deallocates a [`ClearCommand`] instance. + * + * This function is part of the `clearcommand` module. + */ +void sp_clearcommand_free(struct ClearCommand */*notnull*/ instance); + +/** + * Set all pixels to the off state. + * + * Does not affect brightness. + * + * Returns: a new [`ClearCommand`] instance. + * + * This function is part of the `clearcommand` module. + */ +struct ClearCommand */*notnull*/ sp_clearcommand_new(void); /** * Moves the provided [CharGrid] into a new [CharGridCommand], @@ -1535,25 +1503,6 @@ void sp_cmd_chargrid_free(struct CharGridCommand */*notnull*/ instance); */ struct CharGridCommand */*notnull*/ sp_cmd_chargrid_from_grid(CharGrid */*notnull*/ grid); -/** - * Gets a reference to the field `grid` of the [`servicepoint::CharGridCommand`]. - * - * - The returned reference inherits the lifetime of object in which it is contained. - * - The returned pointer may not be used in a function that consumes the instance, e.g. to create a command. - * - * This function is part of the `cmd_chargrid` module. - */ -CharGrid */*notnull*/ sp_cmd_chargrid_get_grid_mut(struct CharGridCommand */*notnull*/ instance); - -/** - * Reads the origin field of the [`CharGridCommand`]. - * - * This function is part of the `cmd_chargrid` module. - */ -void sp_cmd_chargrid_get_origin(struct CharGridCommand */*notnull*/ command, - size_t */*notnull*/ origin_x, - size_t */*notnull*/ origin_y); - /** * Show UTF-8 encoded text on the screen. * @@ -1567,24 +1516,6 @@ struct CharGridCommand */*notnull*/ sp_cmd_chargrid_new(CharGrid */*notnull*/ gr size_t origin_x, size_t origin_y); -/** - * Sets the value of field `grid` of the [`servicepoint::CharGridCommand`]. - * The provided value is moved into the instance, potentially invalidating previously taken references. - * - * This function is part of the `cmd_chargrid` module. - */ -void sp_cmd_chargrid_set_grid(struct CharGridCommand */*notnull*/ instance, - CharGrid */*notnull*/ value); - -/** - * Overwrites the origin field of the [`CharGridCommand`]. - * - * This function is part of the `cmd_chargrid` module. - */ -void sp_cmd_chargrid_set_origin(struct CharGridCommand */*notnull*/ command, - size_t origin_x, - size_t origin_y); - /** * Tries to turn a [CharGridCommand] into a [Packet]. * @@ -1594,45 +1525,6 @@ void sp_cmd_chargrid_set_origin(struct CharGridCommand */*notnull*/ command, */ struct Packet *sp_cmd_chargrid_try_into_packet(struct CharGridCommand */*notnull*/ command); -/** - *Clones a [`ClearCommand`] instance. - * - * This function is part of the `cmd_clear` module. - */ -struct ClearCommand */*notnull*/ sp_cmd_clear_clone(struct ClearCommand */*notnull*/ instance); - -/** - *Deallocates a [`ClearCommand`] instance. - * - * This function is part of the `cmd_clear` module. - */ -void sp_cmd_clear_free(struct ClearCommand */*notnull*/ instance); - -/** - * Set all pixels to the off state. - * - * Does not affect brightness. - * - * Returns: a new [`ClearCommand`] instance. - * - * This function is part of the `cmd_clear` module. - */ -struct ClearCommand */*notnull*/ sp_cmd_clear_new(void); - -/** - *Clones a [`Cp437GridCommand`] instance. - * - * This function is part of the `cmd_cp437grid` module. - */ -struct Cp437GridCommand */*notnull*/ sp_cmd_cp437grid_clone(struct Cp437GridCommand */*notnull*/ instance); - -/** - *Deallocates a [`Cp437GridCommand`] instance. - * - * This function is part of the `cmd_cp437grid` module. - */ -void sp_cmd_cp437grid_free(struct Cp437GridCommand */*notnull*/ instance); - /** * Moves the provided [Cp437Grid] into a new [Cp437GridCommand], * leaving other fields as their default values. @@ -1641,25 +1533,6 @@ void sp_cmd_cp437grid_free(struct Cp437GridCommand */*notnull*/ instance); */ struct Cp437GridCommand */*notnull*/ sp_cmd_cp437grid_from_grid(Cp437Grid */*notnull*/ grid); -/** - * Gets a reference to the field `grid` of the [`servicepoint::Cp437GridCommand`]. - * - * - The returned reference inherits the lifetime of object in which it is contained. - * - The returned pointer may not be used in a function that consumes the instance, e.g. to create a command. - * - * This function is part of the `cmd_cp437grid` module. - */ -Cp437Grid */*notnull*/ sp_cmd_cp437grid_get_grid_mut(struct Cp437GridCommand */*notnull*/ instance); - -/** - * Reads the origin field of the [`Cp437GridCommand`]. - * - * This function is part of the `cmd_cp437grid` module. - */ -void sp_cmd_cp437grid_get_origin(struct Cp437GridCommand */*notnull*/ command, - size_t */*notnull*/ origin_x, - size_t */*notnull*/ origin_y); - /** * Show text on the screen. * @@ -1673,24 +1546,6 @@ struct Cp437GridCommand */*notnull*/ sp_cmd_cp437grid_new(Cp437Grid */*notnull*/ size_t origin_x, size_t origin_y); -/** - * Sets the value of field `grid` of the [`servicepoint::Cp437GridCommand`]. - * The provided value is moved into the instance, potentially invalidating previously taken references. - * - * This function is part of the `cmd_cp437grid` module. - */ -void sp_cmd_cp437grid_set_grid(struct Cp437GridCommand */*notnull*/ instance, - Cp437Grid */*notnull*/ value); - -/** - * Overwrites the origin field of the [`Cp437GridCommand`]. - * - * This function is part of the `cmd_cp437grid` module. - */ -void sp_cmd_cp437grid_set_origin(struct Cp437GridCommand */*notnull*/ command, - size_t origin_x, - size_t origin_y); - /** * Tries to turn a [Cp437GridCommand] into a [Packet]. * @@ -1700,29 +1555,6 @@ void sp_cmd_cp437grid_set_origin(struct Cp437GridCommand */*notnull*/ command, */ struct Packet *sp_cmd_cp437grid_try_into_packet(struct Cp437GridCommand */*notnull*/ command); -/** - *Clones a [`FadeOutCommand`] instance. - * - * This function is part of the `cmd_fadeout` module. - */ -struct FadeOutCommand */*notnull*/ sp_cmd_fadeout_clone(struct FadeOutCommand */*notnull*/ instance); - -/** - *Deallocates a [`FadeOutCommand`] instance. - * - * This function is part of the `cmd_fadeout` module. - */ -void sp_cmd_fadeout_free(struct FadeOutCommand */*notnull*/ instance); - -/** - * A yet-to-be-tested command. - * - * Returns: a new [`FadeOutCommand`] instance. - * - * This function is part of the `cmd_fadeout` module. - */ -struct FadeOutCommand */*notnull*/ sp_cmd_fadeout_new(void); - /** * Clones an [SPCommand] instance. * @@ -1769,76 +1601,6 @@ struct Packet *sp_cmd_generic_into_packet(struct Command command); */ struct Command sp_cmd_generic_try_from_packet(struct Packet */*notnull*/ packet); -/** - *Clones a [`GlobalBrightnessCommand`] instance. - * - * This function is part of the `cmd_globalbrightness` module. - */ -struct GlobalBrightnessCommand */*notnull*/ sp_cmd_globalbrightness_clone(struct GlobalBrightnessCommand */*notnull*/ instance); - -/** - *Deallocates a [`GlobalBrightnessCommand`] instance. - * - * This function is part of the `cmd_globalbrightness` module. - */ -void sp_cmd_globalbrightness_free(struct GlobalBrightnessCommand */*notnull*/ instance); - -/** - * Gets the value of field `brightness` of the [`servicepoint::GlobalBrightnessCommand`]. - * - * This function is part of the `cmd_globalbrightness` module. - */ -Brightness sp_cmd_globalbrightness_get_brightness(struct GlobalBrightnessCommand */*notnull*/ instance); - -/** - * Turns the command into a packet - * - * This function is part of the `cmd_globalbrightness` module. - */ -struct Packet */*notnull*/ sp_cmd_globalbrightness_into_packet(struct GlobalBrightnessCommand */*notnull*/ command); - -/** - * Set the brightness of all tiles to the same value. - * - * Returns: a new [GlobalBrightnessCommand] instance. - * - * This function is part of the `cmd_globalbrightness` module. - */ -struct GlobalBrightnessCommand */*notnull*/ sp_cmd_globalbrightness_new(Brightness brightness); - -/** - * Sets the value of field `brightness` of the [`servicepoint::GlobalBrightnessCommand`]. - * - * This function is part of the `cmd_globalbrightness` module. - */ -void sp_cmd_globalbrightness_set_brightness(struct GlobalBrightnessCommand */*notnull*/ instance, - Brightness value); - -/** - *Clones a [`HardResetCommand`] instance. - * - * This function is part of the `cmd_hardreset` module. - */ -struct HardResetCommand */*notnull*/ sp_cmd_hardreset_clone(struct HardResetCommand */*notnull*/ instance); - -/** - *Deallocates a [`HardResetCommand`] instance. - * - * This function is part of the `cmd_hardreset` module. - */ -void sp_cmd_hardreset_free(struct HardResetCommand */*notnull*/ instance); - -/** - * Kills the udp daemon on the display, which usually results in a restart. - * - * Please do not send this in your normal program flow. - * - * Returns: a new [`HardResetCommand`] instance. - * - * This function is part of the `cmd_hardreset` module. - */ -struct HardResetCommand */*notnull*/ sp_cmd_hardreset_new(void); - /** *Clones a [`Cp437Grid`] instance. * @@ -1967,6 +1729,153 @@ void sp_cp437grid_set(Cp437Grid */*notnull*/ instance, */ size_t sp_cp437grid_width(Cp437Grid */*notnull*/ instance); +/** + *Clones a [`Cp437GridCommand`] instance. + * + * This function is part of the `cp437gridcommand` module. + */ +struct Cp437GridCommand */*notnull*/ sp_cp437gridcommand_clone(struct Cp437GridCommand */*notnull*/ instance); + +/** + *Deallocates a [`Cp437GridCommand`] instance. + * + * This function is part of the `cp437gridcommand` module. + */ +void sp_cp437gridcommand_free(struct Cp437GridCommand */*notnull*/ instance); + +/** + * Gets a reference to the field `grid` of the [`servicepoint::Cp437GridCommand`]. + * + * - The returned reference inherits the lifetime of object in which it is contained. + * - The returned pointer may not be used in a function that consumes the instance, e.g. to create a command. + * + * This function is part of the `cp437gridcommand` module. + */ +Cp437Grid */*notnull*/ sp_cp437gridcommand_get_grid_mut(struct Cp437GridCommand */*notnull*/ instance); + +/** + * Reads the origin field of the [`Cp437GridCommand`]. + * + * This function is part of the `cp437gridcommand` module. + */ +void sp_cp437gridcommand_get_origin(struct Cp437GridCommand */*notnull*/ command, + size_t */*notnull*/ origin_x, + size_t */*notnull*/ origin_y); + +/** + * Sets the value of field `grid` of the [`servicepoint::Cp437GridCommand`]. + * The provided value is moved into the instance, potentially invalidating previously taken references. + * + * This function is part of the `cp437gridcommand` module. + */ +void sp_cp437gridcommand_set_grid(struct Cp437GridCommand */*notnull*/ instance, + Cp437Grid */*notnull*/ value); + +/** + * Overwrites the origin field of the [`Cp437GridCommand`]. + * + * This function is part of the `cp437gridcommand` module. + */ +void sp_cp437gridcommand_set_origin(struct Cp437GridCommand */*notnull*/ command, + size_t origin_x, + size_t origin_y); + +/** + * Calls method [`servicepoint::DisplayBitVec::as_raw_mut_slice`]. + * + * 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 `displaybitvec` module. + */ +struct ByteSlice sp_displaybitvec_as_raw_mut_slice(BitVec */*notnull*/ instance); + +/** + *Clones a [`DisplayBitVec`] instance. + * + * This function is part of the `displaybitvec` module. + */ +BitVec */*notnull*/ sp_displaybitvec_clone(BitVec */*notnull*/ instance); + +/** + * Calls method [`servicepoint::DisplayBitVec::fill`]. + * + * Sets the value of all bits. + * + * # Arguments + * + * - `value`: the value to set all bits to + * + * This function is part of the `displaybitvec` module. + */ +void sp_displaybitvec_fill(BitVec */*notnull*/ instance, bool value); + +/** + *Deallocates a [`DisplayBitVec`] instance. + * + * This function is part of the `displaybitvec` module. + */ +void sp_displaybitvec_free(BitVec */*notnull*/ instance); + +/** + * Calls method [`servicepoint::DisplayBitVec::get`]. + * + * Gets the value of a bit. + * + * # Arguments + * + * - `bit_vec`: instance to read from + * - `index`: the bit index to read + * + * returns: value of the bit + * + * # Panics + * + * - when accessing `index` out of bounds + * + * This function is part of the `displaybitvec` module. + */ +bool sp_displaybitvec_get(BitVec */*notnull*/ instance, size_t index); + +/** + * Calls method [`servicepoint::DisplayBitVec::is_empty`]. + * + * Returns true if length is 0. + * + * This function is part of the `displaybitvec` module. + */ +bool sp_displaybitvec_is_empty(BitVec */*notnull*/ instance); + +/** + * Calls method [`servicepoint::DisplayBitVec::len`]. + * + * Gets the length in bits. + * + * This function is part of the `displaybitvec` module. + */ +size_t sp_displaybitvec_len(BitVec */*notnull*/ instance); + +/** + * Calls method [`servicepoint::DisplayBitVec::set`]. + * + * Sets the value of a bit. + * + * # Arguments + * + * - `index`: the bit index to edit + * - `value`: the value to set the bit to + * + * # Panics + * + * - when accessing `index` out of bounds + * + * This function is part of the `displaybitvec` module. + */ +void sp_displaybitvec_set(BitVec */*notnull*/ instance, + size_t index, + bool value); + /** * 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/). @@ -1975,6 +1884,99 @@ size_t sp_cp437grid_width(Cp437Grid */*notnull*/ instance); */ void sp_envlogger_init(void); +/** + *Clones a [`FadeOutCommand`] instance. + * + * This function is part of the `fadeoutcommand` module. + */ +struct FadeOutCommand */*notnull*/ sp_fadeoutcommand_clone(struct FadeOutCommand */*notnull*/ instance); + +/** + *Deallocates a [`FadeOutCommand`] instance. + * + * This function is part of the `fadeoutcommand` module. + */ +void sp_fadeoutcommand_free(struct FadeOutCommand */*notnull*/ instance); + +/** + * A yet-to-be-tested command. + * + * Returns: a new [`FadeOutCommand`] instance. + * + * This function is part of the `fadeoutcommand` module. + */ +struct FadeOutCommand */*notnull*/ sp_fadeoutcommand_new(void); + +/** + *Clones a [`GlobalBrightnessCommand`] instance. + * + * This function is part of the `globalbrightnesscommand` module. + */ +struct GlobalBrightnessCommand */*notnull*/ sp_globalbrightnesscommand_clone(struct GlobalBrightnessCommand */*notnull*/ instance); + +/** + *Deallocates a [`GlobalBrightnessCommand`] instance. + * + * This function is part of the `globalbrightnesscommand` module. + */ +void sp_globalbrightnesscommand_free(struct GlobalBrightnessCommand */*notnull*/ instance); + +/** + * Gets the value of field `brightness` of the [`servicepoint::GlobalBrightnessCommand`]. + * + * This function is part of the `globalbrightnesscommand` module. + */ +Brightness sp_globalbrightnesscommand_get_brightness(struct GlobalBrightnessCommand */*notnull*/ instance); + +/** + * Turns the command into a packet + * + * This function is part of the `globalbrightnesscommand` module. + */ +struct Packet */*notnull*/ sp_globalbrightnesscommand_into_packet(struct GlobalBrightnessCommand */*notnull*/ command); + +/** + * Set the brightness of all tiles to the same value. + * + * Returns: a new [GlobalBrightnessCommand] instance. + * + * This function is part of the `globalbrightnesscommand` module. + */ +struct GlobalBrightnessCommand */*notnull*/ sp_globalbrightnesscommand_new(Brightness brightness); + +/** + * Sets the value of field `brightness` of the [`servicepoint::GlobalBrightnessCommand`]. + * + * This function is part of the `globalbrightnesscommand` module. + */ +void sp_globalbrightnesscommand_set_brightness(struct GlobalBrightnessCommand */*notnull*/ instance, + Brightness value); + +/** + *Clones a [`HardResetCommand`] instance. + * + * This function is part of the `hardresetcommand` module. + */ +struct HardResetCommand */*notnull*/ sp_hardresetcommand_clone(struct HardResetCommand */*notnull*/ instance); + +/** + *Deallocates a [`HardResetCommand`] instance. + * + * This function is part of the `hardresetcommand` module. + */ +void sp_hardresetcommand_free(struct HardResetCommand */*notnull*/ instance); + +/** + * Kills the udp daemon on the display, which usually results in a restart. + * + * Please do not send this in your normal program flow. + * + * Returns: a new [`HardResetCommand`] instance. + * + * This function is part of the `hardresetcommand` module. + */ +struct HardResetCommand */*notnull*/ sp_hardresetcommand_new(void); + /** *Clones a [`Packet`] instance. * @@ -2079,9 +2081,9 @@ bool sp_sp_u16_to_command_code(uint16_t code, /** *Deallocates a [`UdpSocket`] instance. * - * This function is part of the `udp` module. + * This function is part of the `udpsocket` module. */ -void sp_udp_free(struct UdpSocket */*notnull*/ instance); +void sp_udpsocket_free(struct UdpSocket */*notnull*/ instance); /** * Creates a new instance of [UdpSocket]. @@ -2096,9 +2098,9 @@ void sp_udp_free(struct UdpSocket */*notnull*/ instance); * sp_udp_send_command(connection, sp_command_clear()); * ``` * - * This function is part of the `udp` module. + * This function is part of the `udpsocket` module. */ -struct UdpSocket *sp_udp_open(char */*notnull*/ host); +struct UdpSocket *sp_udpsocket_open(char */*notnull*/ host); /** * Creates a new instance of [UdpSocket]. @@ -2113,13 +2115,13 @@ struct UdpSocket *sp_udp_open(char */*notnull*/ host); * sp_udp_send_command(connection, sp_command_clear()); * ``` * - * This function is part of the `udp` module. + * This function is part of the `udpsocket` module. */ -struct UdpSocket *sp_udp_open_ipv4(uint8_t ip1, - uint8_t ip2, - uint8_t ip3, - uint8_t ip4, - uint16_t port); +struct UdpSocket *sp_udpsocket_open_ipv4(uint8_t ip1, + uint8_t ip2, + uint8_t ip3, + uint8_t ip4, + uint16_t port); /** * Sends a [SPCommand] to the display using the [UdpSocket]. @@ -2134,10 +2136,10 @@ struct UdpSocket *sp_udp_open_ipv4(uint8_t ip1, * sp_udp_send_command(connection, sp_command_brightness(5)); * ``` * - * This function is part of the `udp` module. + * This function is part of the `udpsocket` module. */ -bool sp_udp_send_command(struct UdpSocket */*notnull*/ connection, - struct Command command); +bool sp_udpsocket_send_command(struct UdpSocket */*notnull*/ connection, + struct Command command); /** * Sends a [Header] to the display using the [UdpSocket]. @@ -2150,10 +2152,10 @@ bool sp_udp_send_command(struct UdpSocket */*notnull*/ connection, * sp_udp_send_header(connection, sp_command_brightness(5)); * ``` * - * This function is part of the `udp` module. + * This function is part of the `udpsocket` module. */ -bool sp_udp_send_header(struct UdpSocket */*notnull*/ udp_connection, - struct Header header); +bool sp_udpsocket_send_header(struct UdpSocket */*notnull*/ udp_connection, + struct Header header); /** * Sends a [Packet] to the display using the [UdpSocket]. @@ -2162,10 +2164,10 @@ bool sp_udp_send_header(struct UdpSocket */*notnull*/ udp_connection, * * returns: true in case of success * - * This function is part of the `udp` module. + * This function is part of the `udpsocket` module. */ -bool sp_udp_send_packet(struct UdpSocket */*notnull*/ connection, - struct Packet */*notnull*/ packet); +bool sp_udpsocket_send_packet(struct UdpSocket */*notnull*/ connection, + struct Packet */*notnull*/ packet); #ifdef __cplusplus } // extern "C" diff --git a/src/commands/bitmap_command.rs b/src/commands/bitmap_command.rs index 06cc53f..6fa5357 100644 --- a/src/commands/bitmap_command.rs +++ b/src/commands/bitmap_command.rs @@ -8,14 +8,14 @@ use std::ptr::NonNull; wrap_command!(Bitmap); -wrap_fields!(cmd_bitmap::BitmapCommand; +wrap_fields!(BitmapCommand; prop bitmap: Bitmap { mut get(); move set(value); }; prop compression: CompressionCode { get(); set(value); }; ); -wrap_origin_accessors!(cmd_bitmap::BitmapCommand); +wrap_origin_accessors!(BitmapCommand); -wrap_functions!(cmd_bitmap; +wrap_functions!(associate BitmapCommand; /// Sets a window of pixels to the specified values. /// /// The passed [Bitmap] gets consumed. diff --git a/src/commands/bitvec_command.rs b/src/commands/bitvec_command.rs index 100fc93..fab6a2d 100644 --- a/src/commands/bitvec_command.rs +++ b/src/commands/bitvec_command.rs @@ -11,14 +11,14 @@ use std::ptr::NonNull; wrap_command!(BitVec); -wrap_fields!(cmd_bitvec::BitVecCommand; +wrap_fields!(BitVecCommand; prop bitvec: DisplayBitVec { mut get(); move set(value); }; prop offset: Offset { get(); set(value); }; prop operation: BinaryOperation { get(); set(value); }; prop compression: CompressionCode { get(); set(value); }; ); -wrap_functions!(cmd_bitvec; +wrap_functions!(associate BitVecCommand; /// Set pixel data starting at the pixel offset on screen. /// diff --git a/src/commands/brightness_grid_command.rs b/src/commands/brightness_grid_command.rs index b66952d..8aed3d7 100644 --- a/src/commands/brightness_grid_command.rs +++ b/src/commands/brightness_grid_command.rs @@ -8,13 +8,13 @@ use std::ptr::NonNull; wrap_command!(BrightnessGrid); -wrap_fields!(cmd_brightnessgrid::BrightnessGridCommand; +wrap_fields!(BrightnessGridCommand; prop grid: BrightnessGrid { mut get(); move set(grid); }; ); -wrap_origin_accessors!(cmd_brightnessgrid::BrightnessGridCommand); +wrap_origin_accessors!(BrightnessGridCommand); -wrap_functions!(cmd_brightnessgrid; +wrap_functions!(associate BrightnessGridCommand; /// Set the brightness of individual tiles in a rectangular area of the display. /// diff --git a/src/commands/cc_only_commands.rs b/src/commands/cc_only_commands.rs index 0d72078..a34e5c8 100644 --- a/src/commands/cc_only_commands.rs +++ b/src/commands/cc_only_commands.rs @@ -5,22 +5,18 @@ use servicepoint::{ClearCommand, FadeOutCommand, HardResetCommand}; use std::ptr::NonNull; macro_rules! wrap_cc_only { - ($(#[$meta:meta])*; $command:ident, $prefix:ident, $object_type:ident) => { - wrap_command!($command); - - wrap_functions!($prefix; - $(#[$meta])* - /// - #[doc = concat!(" Returns: a new [`",stringify!($object_type),"`] instance.")] - fn new() -> NonNull<$object_type> { - heap_move_nonnull($object_type) - } - ); - }; - ($(#[$meta:meta])* $command:ident) => { ::paste::paste!{ - wrap_cc_only!($(#[$meta])*; $command, [< cmd_ $command:lower >], [< $command Command >]); + wrap_command!($command); + + wrap_functions!(associate [< $command Command >]; + $(#[$meta])* + /// + #[doc = " Returns: a new [`" [< $command Command >] "`] instance."] + fn new() -> NonNull<[< $command Command >]> { + heap_move_nonnull([< $command Command >]) + } + ); } }; } diff --git a/src/commands/char_grid_command.rs b/src/commands/char_grid_command.rs index f614808..551533e 100644 --- a/src/commands/char_grid_command.rs +++ b/src/commands/char_grid_command.rs @@ -8,11 +8,11 @@ use std::ptr::NonNull; wrap_command!(CharGrid); -wrap_fields!(cmd_chargrid::CharGridCommand; +wrap_fields!(CharGridCommand; prop grid: CharGrid { mut get(); move set(grid); }; ); -wrap_origin_accessors!(cmd_chargrid::CharGridCommand); +wrap_origin_accessors!(CharGridCommand); wrap_functions!(cmd_chargrid; diff --git a/src/commands/cp437_grid_command.rs b/src/commands/cp437_grid_command.rs index 4ecd058..913c393 100644 --- a/src/commands/cp437_grid_command.rs +++ b/src/commands/cp437_grid_command.rs @@ -8,11 +8,11 @@ use std::ptr::NonNull; wrap_command!(Cp437Grid); -wrap_fields!(cmd_cp437grid::Cp437GridCommand; +wrap_fields!(Cp437GridCommand; prop grid: Cp437Grid { mut get(); move set(grid); }; ); -wrap_origin_accessors!(cmd_cp437grid::Cp437GridCommand); +wrap_origin_accessors!(Cp437GridCommand); wrap_functions!(cmd_cp437grid; diff --git a/src/commands/global_brightness_command.rs b/src/commands/global_brightness_command.rs index 1b3fb34..247ef55 100644 --- a/src/commands/global_brightness_command.rs +++ b/src/commands/global_brightness_command.rs @@ -6,7 +6,7 @@ use crate::{ use servicepoint::{Brightness, GlobalBrightnessCommand, Packet}; use std::ptr::NonNull; -wrap_functions!(cmd_globalbrightness; +wrap_functions!(associate GlobalBrightnessCommand; /// Set the brightness of all tiles to the same value. /// @@ -24,8 +24,7 @@ wrap_functions!(cmd_globalbrightness; wrap_command!(GlobalBrightness); -wrap_fields!( - cmd_globalbrightness::GlobalBrightnessCommand; +wrap_fields!(GlobalBrightnessCommand; prop brightness: Brightness { get(); set(value); diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 0fce600..a00ab89 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -15,32 +15,35 @@ pub use cp437_grid_command::*; pub use generic_command::*; macro_rules! wrap_origin_accessors { - ( $prefix:ident :: $object_type:ty ) => { - $crate::macros::wrap_functions!($prefix; - #[doc = concat!(" Reads the origin field of the [`", stringify!($object_type), "`].")] - fn get_origin( - command: NonNull<$object_type>, - origin_x: NonNull, - origin_y: NonNull, - ) { - unsafe { - let origin = &command.as_ref().origin; - *origin_x.as_ptr() = origin.x; - *origin_y.as_ptr() = origin.y; + ( $object_type:ident ) => { + ::paste::paste! { + $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, + ) { + unsafe { + let origin = &command.as_ref().origin; + *origin_x.as_ptr() = origin.x; + *origin_y.as_ptr() = origin.y; + } } - } - #[doc = concat!(" Overwrites the origin field of the [`", stringify!($object_type), "`].")] - fn set_origin( - command: NonNull<$object_type>, - origin_x: usize, - origin_y: usize, - ) { - unsafe { - $crate::macros::nonnull_as_mut!(command).origin = ::servicepoint::Origin::new(origin_x, origin_y); + #[doc = " Overwrites the origin field of the [`" $object_type "`]."] + fn set_origin( + command: NonNull<$object_type>, + origin_x: usize, + origin_y: usize, + ) { + unsafe { + $crate::macros::nonnull_as_mut!(command).origin = + ::servicepoint::Origin::new(origin_x, origin_y); + } } - } - ); + ); + } }; } @@ -62,15 +65,14 @@ macro_rules! derive_command_from { } macro_rules! wrap_command { - ($command:ident, $prefix:ident, $object_type:ident) => { - $crate::macros::wrap_clone!($prefix::$object_type); - $crate::macros::wrap_free!($prefix::$object_type); - + ($command:ident, $object_type:ident) => { + $crate::macros::wrap_clone!($object_type); + $crate::macros::wrap_free!($object_type); $crate::commands::derive_command_from!($command); }; ($command:ident) => { - ::paste::paste!{ - wrap_command!($command, [< cmd_ $command:lower >], [< $command Command >]); + ::paste::paste! { + wrap_command!($command, [< $command Command >]); } }; } diff --git a/src/containers/bitmap.rs b/src/containers/bitmap.rs index 9ebf13a..1d482b4 100644 --- a/src/containers/bitmap.rs +++ b/src/containers/bitmap.rs @@ -9,8 +9,8 @@ use servicepoint::{ }; use std::ptr::NonNull; -wrap_clone!(bitmap::Bitmap); -wrap_free!(bitmap::Bitmap); +wrap_clone!(Bitmap); +wrap_free!(Bitmap); wrap_functions!(bitmap; @@ -105,8 +105,7 @@ wrap_functions!(bitmap; } ); -wrap_methods!( - bitmap::Bitmap; +wrap_methods!(Bitmap; /// Gets the current value at the specified position. /// diff --git a/src/containers/bitvec.rs b/src/containers/bitvec.rs index 4512ac1..b0782c4 100644 --- a/src/containers/bitvec.rs +++ b/src/containers/bitvec.rs @@ -55,11 +55,10 @@ wrap_functions!(bitvec; ); -wrap_clone!(bitvec::DisplayBitVec); -wrap_free!(bitvec::DisplayBitVec); +wrap_clone!(DisplayBitVec); +wrap_free!(DisplayBitVec); -wrap_methods!( - bitvec::DisplayBitVec; +wrap_methods!(DisplayBitVec; /// Gets the value of a bit. /// diff --git a/src/containers/brightness_grid.rs b/src/containers/brightness_grid.rs index 01fc010..8a9d3cc 100644 --- a/src/containers/brightness_grid.rs +++ b/src/containers/brightness_grid.rs @@ -71,11 +71,10 @@ wrap_functions!(brightnessgrid; ); -wrap_clone!(brightnessgrid::BrightnessGrid); -wrap_free!(brightnessgrid::BrightnessGrid); +wrap_clone!(BrightnessGrid); +wrap_free!(BrightnessGrid); -wrap_methods!( - brightnessgrid::BrightnessGrid; +wrap_methods!(BrightnessGrid; /// Gets the current value at the specified position. /// diff --git a/src/containers/byte_slice.rs b/src/containers/byte_slice.rs index 66bdce2..aac6615 100644 --- a/src/containers/byte_slice.rs +++ b/src/containers/byte_slice.rs @@ -36,6 +36,7 @@ impl ByteSlice { unsafe { std::slice::from_raw_parts(self.start, self.length) } } + #[allow(clippy::mut_from_ref, reason = "This is used to get a pointer from the C side")] pub(crate) unsafe fn as_slice_mut(&self) -> &mut [u8] { unsafe { std::slice::from_raw_parts_mut(self.start, self.length) } } diff --git a/src/containers/char_grid.rs b/src/containers/char_grid.rs index a79af3a..f158702 100644 --- a/src/containers/char_grid.rs +++ b/src/containers/char_grid.rs @@ -58,11 +58,10 @@ wrap_functions!(chargrid; ); -wrap_clone!(chargrid::CharGrid); -wrap_free!(chargrid::CharGrid); +wrap_clone!(CharGrid); +wrap_free!(CharGrid); -wrap_methods!( - chargrid::CharGrid; +wrap_methods!(CharGrid; /// Returns the current value at the specified position. /// diff --git a/src/containers/cp437_grid.rs b/src/containers/cp437_grid.rs index a78cecf..5822019 100644 --- a/src/containers/cp437_grid.rs +++ b/src/containers/cp437_grid.rs @@ -50,11 +50,10 @@ wrap_functions!(cp437grid; ); -wrap_clone!(cp437grid::Cp437Grid); -wrap_free!(cp437grid::Cp437Grid); +wrap_clone!(Cp437Grid); +wrap_free!(Cp437Grid); -wrap_methods!( - cp437grid::Cp437Grid; +wrap_methods!(Cp437Grid; /// Gets the current value at the specified position. /// /// # Arguments diff --git a/src/macros.rs b/src/macros.rs index 93e06b8..7cd0a71 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,22 +1,26 @@ macro_rules! wrap_free { - ($prefix:ident :: $typ:ty) => { - $crate::macros::wrap_functions!($prefix; - #[doc = concat!("Deallocates a [`", stringify!($typ), "`] instance.")] - fn free(instance: NonNull<$typ>) { - unsafe { $crate::mem::heap_drop(instance) } - } - ); + ($typ:ident) => { + ::paste::paste! { + $crate::macros::wrap_functions!([< $typ:lower >]; + #[doc = "Deallocates a [`" $typ "`] instance."] + fn free(instance: NonNull<$typ>) { + unsafe { $crate::mem::heap_drop(instance) } + } + ); + } }; } macro_rules! wrap_clone { - ($prefix:ident :: $typ:ty) => { - $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) } - } - ); + ($typ:ident) => { + ::paste::paste! { + $crate::macros::wrap_functions!([< $typ:lower >]; + #[doc = "Clones a [`" $typ "`] instance."] + fn clone(instance: NonNull<$typ>) -> NonNull<$typ> { + unsafe { $crate::mem::heap_clone(instance) } + } + ); + } }; } @@ -35,7 +39,7 @@ macro_rules! nonnull_as_mut { // meta required on purpose, because otherwise the added documentation would suppress warnings macro_rules! wrap_methods { ( - $prefix:ident :: $object_type:ty; + $object_type:ident; $( $(#[$meta:meta])+ $ref_or_mut:ident fn $function:ident($($param_name:ident: $param_type:ty),*) @@ -48,10 +52,9 @@ macro_rules! wrap_methods { )+ ) => { paste::paste! { - $crate::macros::wrap_functions!($prefix; + $crate::macros::wrap_functions!([< $object_type:lower >]; $( - #[doc = concat!(" Calls method [`servicepoint::", stringify!($object_type), - "::", stringify!($function), "`].")] + #[doc = " Calls method [`servicepoint::" $object_type "::" $function "`]."] #[doc = ""] $(#[$meta])* fn $function( @@ -82,7 +85,7 @@ macro_rules! wrap_methods { macro_rules! wrap_fields { ( - $prefix:ident :: $object_type:ty; + $object_type:ident; $( prop $prop_name:ident : $prop_type:ty { $( @@ -118,11 +121,10 @@ macro_rules! wrap_fields { )+ ) => { paste::paste! { - $crate::macros::wrap_functions!($prefix; + $crate::macros::wrap_functions!([< $object_type:lower >]; $( $( - #[doc = concat!(" Gets the value of field `", stringify!($prop_name), - "` of the [`servicepoint::", stringify!($object_type),"`].")] + #[doc = " Gets the value of field `" $prop_name "` of the [`servicepoint::" $object_type "`]."] $($( #[doc = ""] #[$get_meta] @@ -230,6 +232,25 @@ macro_rules! wrap_functions { )+ } }; + ( + associate $object_type:ident; + $( + $(#[$meta:meta])+ + fn $function:ident($($param_name:ident: $param_type:ty),*$(,)?) + $(-> $return_type:ty)? + $block:block + )+ + ) => { + ::paste::paste! { + $crate::macros::wrap_functions!{[< $object_type:lower >]; + $( + $(#[$meta])+ + fn $function($($param_name: $param_type),*) $(-> $return_type)? + $block + )+ + } + } + }; } pub(crate) use { diff --git a/src/packet.rs b/src/packet.rs index 18d63bd..df532b7 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -68,11 +68,10 @@ wrap_functions!(packet; } ); -wrap_clone!(packet::Packet); -wrap_free!(packet::Packet); +wrap_clone!(Packet); +wrap_free!(Packet); -wrap_fields!( - packet::Packet; +wrap_fields!(Packet; prop header: Header { get(); mut get(); diff --git a/src/udp.rs b/src/udp.rs index fd907be..21c067e 100644 --- a/src/udp.rs +++ b/src/udp.rs @@ -10,9 +10,9 @@ use std::{ ptr::NonNull, }; -wrap_free!(udp::UdpSocket); +wrap_free!(UdpSocket); -wrap_functions!(udp; +wrap_functions!(associate UdpSocket; /// Creates a new instance of [UdpSocket]. ///