more type name based naming
This commit is contained in:
parent
8f13ba61f0
commit
8116375fd0
27 changed files with 787 additions and 750 deletions
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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 >])
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<usize>,
|
||||
origin_y: NonNull<usize>,
|
||||
) {
|
||||
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<usize>,
|
||||
origin_y: NonNull<usize>,
|
||||
) {
|
||||
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 >]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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) }
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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].
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue