diff --git a/include/servicepoint.h b/include/servicepoint.h index 805d84b..02f4676 100644 --- a/include/servicepoint.h +++ b/include/servicepoint.h @@ -845,15 +845,15 @@ BrightnessGrid *sp_brightness_grid_load(size_t width, * * # Examples * ```C - * UdpConnection connection = sp_udp_open("127.0.0.1:2342"); + * UdpSocket *connection = sp_udp_open("127.0.0.1:2342"); * if (connection == NULL) * return 1; * - * BrightnessGrid grid = sp_brightness_grid_new(2, 2); + * BrightnessGrid *grid = sp_brightness_grid_new(2, 2); * sp_brightness_grid_set(grid, 0, 0, 0); * sp_brightness_grid_set(grid, 1, 1, 10); * - * TypedCommand command = sp_command_char_brightness(grid); + * TypedCommand *command = sp_command_char_brightness(grid); * sp_udp_free(connection); * ``` */ @@ -1013,6 +1013,12 @@ BitmapCommand */*notnull*/ sp_cmd_bitmap_clone(BitmapCommand */*notnull*/ comman void sp_cmd_bitmap_free(BitmapCommand */*notnull*/ command); +/** + * Move the provided [Bitmap] into a new [BitmapCommand], + * leaving other fields as their default values. + * + * Rust equivalent: [`>::from`] + */ BitmapCommand */*notnull*/ sp_cmd_bitmap_from_bitmap(Bitmap */*notnull*/ bitmap); /** @@ -1475,19 +1481,19 @@ bool sp_u16_to_command_code(uint16_t code, CommandCode *result); /** - * Closes and deallocates a [UdpConnection]. + * Closes and deallocates a [UdpSocket]. */ void sp_udp_free(UdpSocket */*notnull*/ connection); /** - * Creates a new instance of [UdpConnection]. + * Creates a new instance of [UdpSocket]. * * returns: NULL if connection fails, or connected instance * * # Examples * * ```C - * UdpConnection connection = sp_udp_open("172.23.42.29:2342"); + * UdpSocket connection = sp_udp_open("172.23.42.29:2342"); * if (connection != NULL) * sp_udp_send_command(connection, sp_command_clear()); * ``` @@ -1495,14 +1501,14 @@ void sp_udp_free(UdpSocket */*notnull*/ connection); UdpSocket *sp_udp_open(char */*notnull*/ host); /** - * Creates a new instance of [UdpConnection]. + * Creates a new instance of [UdpSocket]. * * returns: NULL if connection fails, or connected instance * * # Examples * * ```C - * UdpConnection connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342); + * UdpSocket connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342); * if (connection != NULL) * sp_udp_send_command(connection, sp_command_clear()); * ``` @@ -1514,7 +1520,7 @@ UdpSocket *sp_udp_open_ipv4(uint8_t ip1, uint16_t port); /** - * Sends a [TypedCommand] to the display using the [UdpConnection]. + * Sends a [TypedCommand] to the display using the [UdpSocket]. * * The passed `command` gets consumed. * @@ -1530,7 +1536,7 @@ bool sp_udp_send_command(UdpSocket */*notnull*/ connection, TypedCommand */*notnull*/ command); /** - * Sends a [Header] to the display using the [UdpConnection]. + * Sends a [Header] to the display using the [UdpSocket]. * * returns: true in case of success * @@ -1543,7 +1549,7 @@ bool sp_udp_send_command(UdpSocket */*notnull*/ connection, bool sp_udp_send_header(UdpSocket */*notnull*/ udp_connection, Header header); /** - * Sends a [Packet] to the display using the [UdpConnection]. + * Sends a [Packet] to the display using the [UdpSocket]. * * The passed `packet` gets consumed. * diff --git a/src/bitmap.rs b/src/bitmap.rs index b8b482f..9e7f4bd 100644 --- a/src/bitmap.rs +++ b/src/bitmap.rs @@ -1,7 +1,6 @@ -use crate::byte_slice::ByteSlice; use crate::{ heap_drop, heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove, - SPBitVec, + byte_slice::ByteSlice, bitvec::SPBitVec, }; use servicepoint::{ Bitmap, BitmapCommand, CompressionCode, DataRef, Grid, Origin, Packet, diff --git a/src/bitvec.rs b/src/bitvec.rs index b988df6..b7743aa 100644 --- a/src/bitvec.rs +++ b/src/bitvec.rs @@ -1,5 +1,5 @@ use crate::{ - heap_drop, heap_move_nonnull, heap_move_ok, heap_remove, ByteSlice, + heap_drop, heap_move_nonnull, heap_move_ok, heap_remove, byte_slice::ByteSlice, }; use servicepoint::{ BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Packet, diff --git a/src/brightness_grid.rs b/src/brightness_grid.rs index 2dd985a..496c53f 100644 --- a/src/brightness_grid.rs +++ b/src/brightness_grid.rs @@ -1,6 +1,6 @@ use crate::{ heap_drop, heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove, - ByteSlice, + byte_slice::ByteSlice, }; use servicepoint::{ Brightness, BrightnessGrid, BrightnessGridCommand, ByteGrid, DataRef, Grid, @@ -15,15 +15,15 @@ use std::ptr::NonNull; /// /// # Examples /// ```C -/// UdpConnection connection = sp_udp_open("127.0.0.1:2342"); +/// UdpSocket *connection = sp_udp_open("127.0.0.1:2342"); /// if (connection == NULL) /// return 1; /// -/// BrightnessGrid grid = sp_brightness_grid_new(2, 2); +/// BrightnessGrid *grid = sp_brightness_grid_new(2, 2); /// sp_brightness_grid_set(grid, 0, 0, 0); /// sp_brightness_grid_set(grid, 1, 1, 10); /// -/// TypedCommand command = sp_command_char_brightness(grid); +/// TypedCommand *command = sp_command_char_brightness(grid); /// sp_udp_free(connection); /// ``` #[no_mangle] diff --git a/src/char_grid.rs b/src/char_grid.rs index e07e8db..42502a7 100644 --- a/src/char_grid.rs +++ b/src/char_grid.rs @@ -1,5 +1,5 @@ use crate::{ - heap_drop, heap_move_nonnull, heap_move_ok, heap_remove, ByteSlice, + heap_drop, heap_move_nonnull, heap_move_ok, heap_remove, byte_slice::ByteSlice, }; use servicepoint::{CharGrid, CharGridCommand, Grid, Origin, Packet}; use std::ptr::NonNull; diff --git a/src/commands/bitmap_command.rs b/src/commands/bitmap_command.rs index 4413a3c..a45a155 100644 --- a/src/commands/bitmap_command.rs +++ b/src/commands/bitmap_command.rs @@ -23,6 +23,10 @@ pub unsafe extern "C" fn sp_cmd_bitmap_new( }) } +/// Move the provided [Bitmap] into a new [BitmapCommand], +/// leaving other fields as their default values. +/// +/// Rust equivalent: [`>::from`] #[no_mangle] pub unsafe extern "C" fn sp_cmd_bitmap_from_bitmap( bitmap: NonNull, diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 90422ff..e4b1d4a 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -3,3 +3,9 @@ mod bitvec_command; mod brightness_grid_command; mod char_grid_command; mod cp437_grid_command; + +pub use bitmap_command::*; +pub use bitvec_command::*; +pub use brightness_grid_command::*; +pub use char_grid_command::*; +pub use cp437_grid_command::*; diff --git a/src/cp437_grid.rs b/src/cp437_grid.rs index 5a3daab..c39118e 100644 --- a/src/cp437_grid.rs +++ b/src/cp437_grid.rs @@ -1,6 +1,6 @@ use crate::{ heap_drop, heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove, - ByteSlice, + byte_slice::ByteSlice, }; use servicepoint::{ Cp437Grid, Cp437GridCommand, DataRef, Grid, Origin, Packet, diff --git a/src/lib.rs b/src/lib.rs index 924a729..c98318a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ //! #include "servicepoint.h" //! //! int main(void) { -//! UdpConnection *connection = sp_udp_open("172.23.42.29:2342"); +//! UdpSocket *connection = sp_udp_open("172.23.42.29:2342"); //! if (connection == NULL) //! return 1; //! @@ -25,28 +25,18 @@ //! } //! ``` -pub use crate::bitmap::*; -pub use crate::bitvec::*; -pub use crate::brightness_grid::*; -pub use crate::byte_slice::*; -pub use crate::char_grid::*; -pub use crate::cp437_grid::*; -pub use crate::packet::*; -pub use crate::typed_command::*; -pub use crate::udp::*; -pub use servicepoint::CommandCode; use std::ptr::NonNull; -mod bitmap; -mod bitvec; -mod brightness_grid; -mod byte_slice; -mod char_grid; -mod commands; -mod cp437_grid; -mod packet; -mod typed_command; -mod udp; +pub mod bitmap; +pub mod bitvec; +pub mod brightness_grid; +pub mod byte_slice; +pub mod char_grid; +pub mod commands; +pub mod cp437_grid; +pub mod packet; +pub mod typed_command; +pub mod udp; use std::time::Duration; diff --git a/src/packet.rs b/src/packet.rs index a454732..ea41597 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -1,5 +1,5 @@ use crate::{ - heap_drop, heap_move_nonnull, heap_move_ok, heap_remove, ByteSlice, + heap_drop, heap_move_nonnull, heap_move_ok, heap_remove, byte_slice::ByteSlice, }; use servicepoint::{CommandCode, Header, Packet, TypedCommand}; use std::ptr::NonNull; diff --git a/src/udp.rs b/src/udp.rs index bc8acc3..b75f13d 100644 --- a/src/udp.rs +++ b/src/udp.rs @@ -4,14 +4,14 @@ use std::ffi::{c_char, CStr}; use std::net::{Ipv4Addr, SocketAddrV4, UdpSocket}; use std::ptr::NonNull; -/// Creates a new instance of [UdpConnection]. +/// Creates a new instance of [UdpSocket]. /// /// returns: NULL if connection fails, or connected instance /// /// # Examples /// /// ```C -/// UdpConnection connection = sp_udp_open("172.23.42.29:2342"); +/// UdpSocket connection = sp_udp_open("172.23.42.29:2342"); /// if (connection != NULL) /// sp_udp_send_command(connection, sp_command_clear()); /// ``` @@ -24,14 +24,14 @@ pub unsafe extern "C" fn sp_udp_open(host: NonNull) -> *mut UdpSocket { heap_move_ok(UdpSocket::bind_connect(host)) } -/// Creates a new instance of [UdpConnection]. +/// Creates a new instance of [UdpSocket]. /// /// returns: NULL if connection fails, or connected instance /// /// # Examples /// /// ```C -/// UdpConnection connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342); +/// UdpSocket connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342); /// if (connection != NULL) /// sp_udp_send_command(connection, sp_command_clear()); /// ``` @@ -47,7 +47,7 @@ pub unsafe extern "C" fn sp_udp_open_ipv4( heap_move_ok(UdpSocket::bind_connect(addr)) } -/// Sends a [Packet] to the display using the [UdpConnection]. +/// Sends a [Packet] to the display using the [UdpSocket]. /// /// The passed `packet` gets consumed. /// @@ -61,7 +61,7 @@ pub unsafe extern "C" fn sp_udp_send_packet( unsafe { connection.as_ref().send(&Vec::from(packet)) }.is_ok() } -/// Sends a [TypedCommand] to the display using the [UdpConnection]. +/// Sends a [TypedCommand] to the display using the [UdpSocket]. /// /// The passed `command` gets consumed. /// @@ -81,7 +81,7 @@ pub unsafe extern "C" fn sp_udp_send_command( unsafe { connection.as_ref().send_command(command) }.is_some() } -/// Sends a [Header] to the display using the [UdpConnection]. +/// Sends a [Header] to the display using the [UdpSocket]. /// /// returns: true in case of success /// @@ -104,7 +104,7 @@ pub unsafe extern "C" fn sp_udp_send_header( .is_ok() } -/// Closes and deallocates a [UdpConnection]. +/// Closes and deallocates a [UdpSocket]. #[no_mangle] pub unsafe extern "C" fn sp_udp_free(connection: NonNull) { unsafe { heap_drop(connection) }