Compare commits

...

2 commits

Author SHA1 Message Date
Vinzenz Schroeter c65b735f57 generic wrap
Some checks failed
Rust / build-gnu-apt (pull_request) Successful in 2m4s
Rust / build-size-gnu-unstable (pull_request) Failing after 2m44s
2025-06-26 22:36:57 +02:00
Vinzenz Schroeter 5beea6151a wip generic wrap 2025-06-26 20:42:31 +02:00
16 changed files with 840 additions and 783 deletions

View file

@ -1,20 +1,19 @@
use crate::{ use crate::{
commands::{wrap_command, wrap_origin_accessors}, commands::{wrap_command, wrap_origin_accessors},
macros::{wrap_fields, wrap_functions}, macros::wrap,
}; };
use servicepoint::{Bitmap, BitmapCommand, CompressionCode, Origin}; use servicepoint::{Bitmap, BitmapCommand, CompressionCode, Origin};
use std::ptr::NonNull; use std::ptr::NonNull;
wrap_command!(Bitmap); wrap_command!(Bitmap);
wrap_fields!(BitmapCommand;
prop bitmap: Bitmap { get mut; set move; };
prop compression: CompressionCode { get; set; };
);
wrap_origin_accessors!(BitmapCommand); wrap_origin_accessors!(BitmapCommand);
wrap_functions!(associate BitmapCommand; wrap! {
BitmapCommand {
properties:
prop bitmap: Bitmap { get mut; set move; };
prop compression: CompressionCode { get; set; };
functions:
/// Sets a window of pixels to the specified values. /// Sets a window of pixels to the specified values.
/// ///
/// The passed [Bitmap] gets consumed. /// The passed [Bitmap] gets consumed.
@ -40,4 +39,5 @@ wrap_functions!(associate BitmapCommand;
fn from_bitmap(bitmap: move NonNull<Bitmap>) -> move NonNull<BitmapCommand> { fn from_bitmap(bitmap: move NonNull<Bitmap>) -> move NonNull<BitmapCommand> {
bitmap.into() bitmap.into()
}; };
); }
}

View file

@ -1,7 +1,4 @@
use crate::{ use crate::{commands::wrap_command, macros::wrap};
commands::wrap_command,
macros::{wrap_fields, wrap_functions},
};
use servicepoint::{ use servicepoint::{
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Offset, BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Offset,
}; };
@ -9,14 +6,14 @@ use std::ptr::NonNull;
wrap_command!(BitVec); wrap_command!(BitVec);
wrap_fields!(BitVecCommand; wrap!(
BitVecCommand {
properties:
prop bitvec: DisplayBitVec { get mut; set move; }; prop bitvec: DisplayBitVec { get mut; set move; };
prop offset: Offset { get; set; }; prop offset: Offset { get; set; };
prop operation: BinaryOperation { get; set; }; prop operation: BinaryOperation { get; set; };
prop compression: CompressionCode { get; set; }; prop compression: CompressionCode { get; set; };
); functions:
wrap_functions!(associate BitVecCommand;
/// Set pixel data starting at the pixel offset on screen. /// Set pixel data starting at the pixel offset on screen.
/// ///
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning /// The screen will continuously overwrite more pixel data without regarding the offset, meaning
@ -42,4 +39,5 @@ wrap_functions!(associate BitVecCommand;
compression, compression,
} }
}; };
}
); );

View file

@ -1,19 +1,18 @@
use crate::{ use crate::{
commands::{wrap_command, wrap_origin_accessors}, commands::{wrap_command, wrap_origin_accessors},
macros::{wrap_fields, wrap_functions}, macros::wrap,
}; };
use servicepoint::{BrightnessGrid, BrightnessGridCommand, Origin}; use servicepoint::{BrightnessGrid, BrightnessGridCommand, Origin};
use std::ptr::NonNull; use std::ptr::NonNull;
wrap_command!(BrightnessGrid); wrap_command!(BrightnessGrid);
wrap_fields!(BrightnessGridCommand;
prop grid: BrightnessGrid { get mut; set move; };
);
wrap_origin_accessors!(BrightnessGridCommand); wrap_origin_accessors!(BrightnessGridCommand);
wrap_functions!(associate BrightnessGridCommand; wrap!(
BrightnessGridCommand {
properties:
prop grid: BrightnessGrid { get mut; set move; };
functions:
/// Set the brightness of individual tiles in a rectangular area of the display. /// Set the brightness of individual tiles in a rectangular area of the display.
/// ///
/// The passed [BrightnessGrid] gets consumed. /// The passed [BrightnessGrid] gets consumed.
@ -35,4 +34,5 @@ wrap_functions!(associate BrightnessGridCommand;
fn from_grid(grid: move NonNull<BrightnessGrid>) -> move NonNull<BrightnessGridCommand> { fn from_grid(grid: move NonNull<BrightnessGrid>) -> move NonNull<BrightnessGridCommand> {
grid.into() grid.into()
}; };
}
); );

View file

@ -1,4 +1,4 @@
use crate::{commands::wrap_command, macros::wrap_functions}; use crate::commands::wrap_command;
use servicepoint::{ClearCommand, FadeOutCommand, HardResetCommand}; use servicepoint::{ClearCommand, FadeOutCommand, HardResetCommand};
macro_rules! wrap_cc_only { macro_rules! wrap_cc_only {
@ -6,14 +6,17 @@ macro_rules! wrap_cc_only {
::paste::paste!{ ::paste::paste!{
wrap_command!($command); wrap_command!($command);
wrap_functions!(associate [< $command Command >]; $crate::macros::wrap!{
[< $command Command >] {
functions:
$(#[$meta])* $(#[$meta])*
/// ///
#[doc = " Returns: a new [`" [< $command Command >] "`] instance."] #[doc = " Returns: a new [`" [< $command Command >] "`] instance."]
fn new() -> move ::core::ptr::NonNull<[< $command Command >]> { fn new() -> move ::core::ptr::NonNull<[< $command Command >]> {
[< $command Command >] [< $command Command >]
}; };
); }
}
} }
}; };
} }

View file

@ -1,19 +1,18 @@
use crate::{ use crate::{
commands::{wrap_command, wrap_origin_accessors}, commands::{wrap_command, wrap_origin_accessors},
macros::{wrap_fields, wrap_functions}, macros::wrap,
}; };
use servicepoint::{CharGrid, CharGridCommand, Origin}; use servicepoint::{CharGrid, CharGridCommand, Origin};
use std::ptr::NonNull; use std::ptr::NonNull;
wrap_command!(CharGrid); wrap_command!(CharGrid);
wrap_fields!(CharGridCommand;
prop grid: CharGrid { get mut; set move; };
);
wrap_origin_accessors!(CharGridCommand); wrap_origin_accessors!(CharGridCommand);
wrap_functions!(associate CharGridCommand; wrap!(
CharGridCommand {
properties:
prop grid: CharGrid { get mut; set move; };
functions:
/// Show UTF-8 encoded text on the screen. /// Show UTF-8 encoded text on the screen.
/// ///
/// The passed [CharGrid] gets consumed. /// The passed [CharGrid] gets consumed.
@ -35,4 +34,5 @@ wrap_functions!(associate CharGridCommand;
fn from_grid(grid: move NonNull<CharGrid>) -> move NonNull<CharGridCommand> { fn from_grid(grid: move NonNull<CharGrid>) -> move NonNull<CharGridCommand> {
grid.into() grid.into()
}; };
}
); );

View file

@ -1,19 +1,18 @@
use crate::{ use crate::{
commands::{wrap_command, wrap_origin_accessors}, commands::{wrap_command, wrap_origin_accessors},
macros::{wrap_fields, wrap_functions}, macros::wrap,
}; };
use servicepoint::{Cp437Grid, Cp437GridCommand, Origin}; use servicepoint::{Cp437Grid, Cp437GridCommand, Origin};
use std::ptr::NonNull; use std::ptr::NonNull;
wrap_command!(Cp437Grid); wrap_command!(Cp437Grid);
wrap_fields!(Cp437GridCommand;
prop grid: Cp437Grid { get mut; set move; };
);
wrap_origin_accessors!(Cp437GridCommand); wrap_origin_accessors!(Cp437GridCommand);
wrap_functions!(associate Cp437GridCommand; wrap!(
Cp437GridCommand {
properties:
prop grid: Cp437Grid { get mut; set move; };
functions:
/// Show text on the screen. /// Show text on the screen.
/// ///
/// The text is sent in the form of a 2D grid of [CP-437] encoded characters. /// The text is sent in the form of a 2D grid of [CP-437] encoded characters.
@ -35,4 +34,5 @@ wrap_functions!(associate Cp437GridCommand;
fn from_grid(grid: move NonNull<Cp437Grid>) -> move NonNull<Cp437GridCommand> { fn from_grid(grid: move NonNull<Cp437Grid>) -> move NonNull<Cp437GridCommand> {
grid.into() grid.into()
}; };
}
); );

View file

@ -1,5 +1,5 @@
use crate::{ use crate::{
macros::{derive_clone, derive_free, wrap_functions, wrap_methods}, macros::{derive_clone, derive_free, wrap},
mem::{ mem::{
heap_clone, heap_drop, heap_move, heap_move_nonnull, heap_move_ok, heap_clone, heap_drop, heap_move, heap_move_nonnull, heap_move_ok,
heap_remove, heap_remove,
@ -69,8 +69,6 @@ impl GenericCommand {
}; };
} }
derive_clone!(GenericCommand);
impl Clone for GenericCommand { impl Clone for GenericCommand {
fn clone(&self) -> Self { fn clone(&self) -> Self {
unsafe { unsafe {
@ -144,8 +142,6 @@ impl Clone for GenericCommand {
} }
} }
derive_free!(GenericCommand);
impl Drop for GenericCommand { impl Drop for GenericCommand {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
@ -172,7 +168,12 @@ impl Drop for GenericCommand {
} }
} }
wrap_functions!(associate GenericCommand; derive_clone!(GenericCommand);
derive_free!(GenericCommand);
wrap! {
GenericCommand {
functions:
/// Tries to turn a [Packet] into a [GenericCommand]. /// Tries to turn a [Packet] into a [GenericCommand].
/// ///
/// The packet is dropped in the process. /// The packet is dropped in the process.
@ -248,9 +249,7 @@ wrap_functions!(associate GenericCommand;
data: CommandUnion { null: null_mut() }, data: CommandUnion { null: null_mut() },
}) })
}; };
); methods:
wrap_methods! { GenericCommand;
/// Tries to turn a [GenericCommand] into a [Packet]. /// Tries to turn a [GenericCommand] into a [Packet].
/// The [GenericCommand] gets consumed. /// The [GenericCommand] gets consumed.
/// ///
@ -290,4 +289,5 @@ wrap_methods! { GenericCommand;
} }
} }
}; };
}
} }

View file

@ -1,21 +1,19 @@
use crate::{ use crate::{commands::wrap_command, macros::wrap};
commands::wrap_command,
macros::{wrap_fields, wrap_functions},
};
use servicepoint::{Brightness, GlobalBrightnessCommand}; use servicepoint::{Brightness, GlobalBrightnessCommand};
use std::ptr::NonNull; use std::ptr::NonNull;
wrap_functions!(associate GlobalBrightnessCommand; wrap_command!(GlobalBrightness);
wrap!(
GlobalBrightnessCommand {
properties:
prop brightness: Brightness { get; set; };
functions:
/// Set the brightness of all tiles to the same value. /// Set the brightness of all tiles to the same value.
/// ///
/// Returns: a new [GlobalBrightnessCommand] instance. /// Returns: a new [GlobalBrightnessCommand] instance.
fn new(brightness: val Brightness) -> move NonNull<GlobalBrightnessCommand> { fn new(brightness: val Brightness) -> move NonNull<GlobalBrightnessCommand> {
GlobalBrightnessCommand::from(brightness) GlobalBrightnessCommand::from(brightness)
}; };
); }
wrap_command!(GlobalBrightness);
wrap_fields!(GlobalBrightnessCommand;
prop brightness: Brightness { get; set; };
); );

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
containers::{wrap_grid, ByteSlice}, containers::{wrap_grid, ByteSlice},
macros::{wrap_functions, wrap_methods}, macros::wrap,
}; };
use servicepoint::{ use servicepoint::{
Bitmap, BitmapCommand, CompressionCode, DataRef, DisplayBitVec, Grid, Bitmap, BitmapCommand, CompressionCode, DataRef, DisplayBitVec, Grid,
@ -10,7 +10,9 @@ use std::ptr::NonNull;
wrap_grid!(Bitmap, bool); wrap_grid!(Bitmap, bool);
wrap_functions!(associate Bitmap; wrap! {
Bitmap {
functions:
/// Creates a new [Bitmap] with the specified dimensions. /// Creates a new [Bitmap] with the specified dimensions.
/// ///
/// # Arguments /// # Arguments
@ -72,9 +74,8 @@ wrap_functions!(associate Bitmap;
) -> move_ok *mut Bitmap { ) -> move_ok *mut Bitmap {
Bitmap::from_bitvec(width, bitvec) Bitmap::from_bitvec(width, bitvec)
}; };
);
wrap_methods!(Bitmap; methods:
/// Consumes the Bitmap and returns the contained BitVec. /// Consumes the Bitmap and returns the contained BitVec.
fn into_bitvec(move bitmap) -> move NonNull<DisplayBitVec> { fn into_bitvec(move bitmap) -> move NonNull<DisplayBitVec> {
bitmap.into() bitmap.into()
@ -97,4 +98,5 @@ wrap_methods!(Bitmap;
/// ///
/// The returned memory is valid for the lifetime of the bitmap. /// The returned memory is valid for the lifetime of the bitmap.
fn data_ref_mut(mut instance) -> slice ByteSlice; fn data_ref_mut(mut instance) -> slice ByteSlice;
); }
}

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
containers::{wrap_container, ByteSlice}, containers::{wrap_container, ByteSlice},
macros::{wrap_functions, wrap_methods}, macros::wrap,
}; };
use servicepoint::{ use servicepoint::{
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Packet, BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Packet,
@ -9,7 +9,9 @@ use std::ptr::NonNull;
wrap_container!(DisplayBitVec); wrap_container!(DisplayBitVec);
wrap_functions!(associate DisplayBitVec; wrap! {
DisplayBitVec {
functions:
/// Creates a new [DisplayBitVec] instance. /// Creates a new [DisplayBitVec] instance.
/// ///
/// # Arguments /// # Arguments
@ -31,9 +33,8 @@ wrap_functions!(associate DisplayBitVec;
fn load(data: slice ByteSlice) -> move NonNull<DisplayBitVec> { fn load(data: slice ByteSlice) -> move NonNull<DisplayBitVec> {
DisplayBitVec::from_slice(data) DisplayBitVec::from_slice(data)
}; };
);
wrap_methods!(DisplayBitVec; methods:
/// Creates a [BitVecCommand] and immediately turns that into a [Packet]. /// Creates a [BitVecCommand] and immediately turns that into a [Packet].
/// ///
/// The provided [DisplayBitVec] gets consumed. /// The provided [DisplayBitVec] gets consumed.
@ -98,4 +99,5 @@ wrap_methods!(DisplayBitVec;
/// ///
/// The returned memory is valid for the lifetime of the bitvec. /// The returned memory is valid for the lifetime of the bitvec.
fn as_raw_mut_slice(mut instance) -> slice ByteSlice; fn as_raw_mut_slice(mut instance) -> slice ByteSlice;
); }
}

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
containers::{wrap_grid, ByteSlice}, containers::{wrap_grid, ByteSlice},
macros::{wrap_functions, wrap_methods}, macros::wrap,
}; };
use servicepoint::{ use servicepoint::{
Brightness, BrightnessGrid, BrightnessGridCommand, ByteGrid, DataRef, Grid, Brightness, BrightnessGrid, BrightnessGridCommand, ByteGrid, DataRef, Grid,
@ -10,7 +10,9 @@ use std::{mem::transmute, ptr::NonNull};
wrap_grid!(BrightnessGrid, Brightness); wrap_grid!(BrightnessGrid, Brightness);
wrap_functions!(associate BrightnessGrid; wrap! {
BrightnessGrid {
functions:
/// Creates a new [BrightnessGrid] with the specified dimensions. /// Creates a new [BrightnessGrid] with the specified dimensions.
/// ///
/// returns: [BrightnessGrid] initialized to 0. /// returns: [BrightnessGrid] initialized to 0.
@ -45,9 +47,8 @@ wrap_functions!(associate BrightnessGrid;
ByteGrid::load(width, height, data) ByteGrid::load(width, height, data)
.map(move |grid| grid.map(Brightness::saturating_from)) .map(move |grid| grid.map(Brightness::saturating_from))
}; };
);
wrap_methods!(BrightnessGrid; methods:
/// Creates a [BrightnessGridCommand] and immediately turns that into a [Packet]. /// Creates a [BrightnessGridCommand] and immediately turns that into a [Packet].
/// ///
/// The provided [BrightnessGrid] gets consumed. /// The provided [BrightnessGrid] gets consumed.
@ -72,4 +73,5 @@ wrap_methods!(BrightnessGrid;
transmute::<&mut [Brightness], &mut [u8]>(br_slice) transmute::<&mut [Brightness], &mut [u8]>(br_slice)
} }
}; };
); }
}

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
containers::{derive_get_width_height, wrap_container, ByteSlice}, containers::{derive_get_width_height, wrap_container, ByteSlice},
macros::{wrap_functions, wrap_methods}, macros::wrap,
}; };
use servicepoint::{CharGrid, CharGridCommand, Grid, Origin, Packet}; use servicepoint::{CharGrid, CharGridCommand, Grid, Origin, Packet};
use std::ptr::NonNull; use std::ptr::NonNull;
@ -8,7 +8,9 @@ use std::ptr::NonNull;
wrap_container!(CharGrid); wrap_container!(CharGrid);
derive_get_width_height!(CharGrid); derive_get_width_height!(CharGrid);
wrap_functions!(associate CharGrid; wrap! {
CharGrid {
functions:
/// Creates a new [CharGrid] with the specified dimensions. /// Creates a new [CharGrid] with the specified dimensions.
/// ///
/// returns: [CharGrid] initialized to 0. /// returns: [CharGrid] initialized to 0.
@ -31,10 +33,7 @@ wrap_functions!(associate CharGrid;
fn load(width: val usize, height: val usize, data: slice ByteSlice) -> move_ok *mut CharGrid { fn load(width: val usize, height: val usize, data: slice ByteSlice) -> move_ok *mut CharGrid {
CharGrid::load_utf8(width, height, data.to_vec()) CharGrid::load_utf8(width, height, data.to_vec())
}; };
); methods:
wrap_methods!(CharGrid;
/// Returns the current value at the specified position. /// Returns the current value at the specified position.
/// ///
/// # Arguments /// # Arguments
@ -86,4 +85,5 @@ wrap_methods!(CharGrid;
origin: Origin::new(x, y), origin: Origin::new(x, y),
}) })
}; };
); }
}

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
containers::{wrap_grid, ByteSlice}, containers::{wrap_grid, ByteSlice},
macros::{wrap_functions, wrap_methods}, macros::wrap,
}; };
use servicepoint::{ use servicepoint::{
Cp437Grid, Cp437GridCommand, DataRef, Grid, Origin, Packet, Cp437Grid, Cp437GridCommand, DataRef, Grid, Origin, Packet,
@ -9,7 +9,9 @@ use std::ptr::NonNull;
wrap_grid!(Cp437Grid, u8); wrap_grid!(Cp437Grid, u8);
wrap_functions!(associate Cp437Grid; wrap! {
Cp437Grid {
functions:
/// Creates a new [Cp437Grid] with the specified dimensions. /// Creates a new [Cp437Grid] with the specified dimensions.
/// ///
/// returns: [Cp437Grid] initialized to 0. /// returns: [Cp437Grid] initialized to 0.
@ -21,9 +23,8 @@ wrap_functions!(associate Cp437Grid;
fn load(width: val usize, height: val usize, data: slice ByteSlice) -> move_some *mut Cp437Grid { fn load(width: val usize, height: val usize, data: slice ByteSlice) -> move_some *mut Cp437Grid {
Cp437Grid::load(width, height, data) Cp437Grid::load(width, height, data)
}; };
);
wrap_methods!(Cp437Grid; methods:
/// Creates a [Cp437GridCommand] and immediately turns that into a [Packet]. /// Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
/// ///
/// The provided [Cp437Grid] gets consumed. /// The provided [Cp437Grid] gets consumed.
@ -40,4 +41,5 @@ wrap_methods!(Cp437Grid;
/// ///
/// The returned memory is valid for the lifetime of the instance. /// The returned memory is valid for the lifetime of the instance.
fn data_ref_mut(mut instance) -> slice ByteSlice; fn data_ref_mut(mut instance) -> slice ByteSlice;
); }
}

View file

@ -263,8 +263,61 @@ macro_rules! wrap_functions {
}; };
} }
macro_rules! wrap {
(
$object_type:ident {
$(
properties:
$(
prop $prop_name:ident : $prop_type:ty { $($accessor:ident $($modifier:ident)?;)+ };
)*
)?
$(
functions:
$(
$(#[$fn_meta:meta])+
fn $fn_name:ident($($fn_param_name:ident: $fn_param_modifier:ident $fn_param_type:ty),*$(,)?)
$(-> $fn_return_modifier:ident $fn_return_type:ty)?
$fn_block:block;
)*
)?
$(
methods:
$(
$(#[$method_meta:meta])+
fn $method_name:ident($method_instance_modifier:ident $method_instance:ident $(, $($method_param_name:ident: $method_param_modifier:ident $method_param_type:ty),*)?)
$(-> $method_return_modifier:ident $method_return_type:ty)?
$($method_impl:block)?;
)*
)?
}
) => {
$($(
$crate::macros::wrap_fields!($object_type;
prop $prop_name : $prop_type { $($accessor $($modifier)?;)+ };
);
)*)?
$($(
$crate::macros::wrap_functions!(associate $object_type;
$(#[$fn_meta])+
fn $fn_name($($fn_param_name: $fn_param_modifier $fn_param_type),*)
$(-> $fn_return_modifier $fn_return_type)?
$fn_block;
);
)*)?
$($(
$crate::macros::wrap_method!($object_type;
$(#[$method_meta])+
fn $method_name($method_instance_modifier $method_instance $(, $($method_param_name: $method_param_modifier $method_param_type),*)?)
$(-> $method_return_modifier $method_return_type)?
$($method_impl)?;
);
)*)?
};
}
pub(crate) use { pub(crate) use {
apply_param_modifier, apply_return_modifier, derive_clone, derive_free, apply_param_modifier, apply_return_modifier, derive_clone, derive_free,
wrap_fields, wrap_fields_accessor, wrap_function, wrap_functions, wrap, wrap_fields, wrap_fields_accessor, wrap_function, wrap_functions,
wrap_method, wrap_methods, wrap_method, wrap_methods,
}; };

View file

@ -1,13 +1,18 @@
use crate::{ use crate::{
containers::ByteSlice, containers::ByteSlice,
macros::{ macros::{derive_clone, derive_free, wrap, wrap_functions},
derive_clone, derive_free, wrap_fields, wrap_functions, wrap_methods,
},
}; };
use servicepoint::{CommandCode, Header, Packet}; use servicepoint::{CommandCode, Header, Packet};
use std::ptr::NonNull; use std::ptr::NonNull;
wrap_functions!(associate Packet; derive_clone!(Packet);
derive_free!(Packet);
wrap! {
Packet {
properties:
prop header: Header { get; get mut; set; };
functions:
/// Tries to load a [Packet] from the passed array with the specified length. /// Tries to load a [Packet] from the passed array with the specified length.
/// ///
/// returns: NULL in case of an error, pointer to the allocated packet otherwise /// returns: NULL in case of an error, pointer to the allocated packet otherwise
@ -27,16 +32,7 @@ wrap_functions!(associate Packet;
Packet { header, payload } Packet { header, payload }
}; };
); methods:
derive_clone!(Packet);
derive_free!(Packet);
wrap_fields!(Packet;
prop header: Header { get; get mut; set; };
);
wrap_methods! { Packet;
/// Returns a pointer to the current payload of the provided packet. /// Returns a pointer to the current payload of the provided packet.
/// ///
/// Returns an [ByteSlice::INVALID] instance in case the packet does not have any payload. /// Returns an [ByteSlice::INVALID] instance in case the packet does not have any payload.
@ -70,10 +66,10 @@ wrap_methods! { Packet;
packet.serialize_to(buffer.as_slice_mut()).unwrap_or(0) packet.serialize_to(buffer.as_slice_mut()).unwrap_or(0)
} }
}; };
}
} }
wrap_functions!(sp; wrap_functions!(sp;
/// Converts u16 into [CommandCode]. /// Converts u16 into [CommandCode].
/// ///
/// If the provided value is not valid, false is returned and result is not changed. /// If the provided value is not valid, false is returned and result is not changed.

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
commands::{CommandTag, GenericCommand}, commands::{CommandTag, GenericCommand},
macros::{derive_free, wrap_functions, wrap_methods}, macros::{derive_free, wrap},
mem::heap_remove, mem::heap_remove,
}; };
use servicepoint::{Header, Packet, UdpSocketExt}; use servicepoint::{Header, Packet, UdpSocketExt};
@ -12,7 +12,9 @@ use std::{
derive_free!(UdpSocket); derive_free!(UdpSocket);
wrap_functions!(associate UdpSocket; wrap! {
UdpSocket {
functions:
/// Creates a new instance of [UdpSocket]. /// Creates a new instance of [UdpSocket].
/// ///
/// returns: NULL if connection fails, or connected instance /// returns: NULL if connection fails, or connected instance
@ -46,9 +48,7 @@ wrap_functions!(associate UdpSocket;
let addr = SocketAddrV4::new(Ipv4Addr::from([ip1, ip2, ip3, ip4]), port); let addr = SocketAddrV4::new(Ipv4Addr::from([ip1, ip2, ip3, ip4]), port);
UdpSocket::bind_connect(addr) UdpSocket::bind_connect(addr)
}; };
); methods:
wrap_methods! {UdpSocket;
/// Sends a [Packet] to the display using the [UdpSocket]. /// Sends a [Packet] to the display using the [UdpSocket].
/// ///
/// The passed `packet` gets consumed. /// The passed `packet` gets consumed.
@ -105,6 +105,7 @@ wrap_methods! {UdpSocket;
}; };
udp_connection.send(&Vec::from(packet)).is_ok() udp_connection.send(&Vec::from(packet)).is_ok()
}; };
}
} }
mod _hidden { mod _hidden {