add derives
This commit is contained in:
parent
c65b735f57
commit
363609c663
|
@ -1,15 +1,10 @@
|
|||
use crate::{
|
||||
commands::{wrap_command, wrap_origin_accessors},
|
||||
macros::wrap,
|
||||
};
|
||||
use crate::macros::wrap;
|
||||
use servicepoint::{Bitmap, BitmapCommand, CompressionCode, Origin};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_command!(Bitmap);
|
||||
wrap_origin_accessors!(BitmapCommand);
|
||||
|
||||
wrap! {
|
||||
BitmapCommand {
|
||||
derives: crate::commands::derive_command[Bitmap], crate::commands::derive_origin_accessors;
|
||||
properties:
|
||||
prop bitmap: Bitmap { get mut; set move; };
|
||||
prop compression: CompressionCode { get; set; };
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
use crate::{commands::wrap_command, macros::wrap};
|
||||
use crate::macros::wrap;
|
||||
use servicepoint::{
|
||||
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Offset,
|
||||
};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_command!(BitVec);
|
||||
|
||||
wrap!(
|
||||
BitVecCommand {
|
||||
derives: crate::commands::derive_command[BitVec];
|
||||
properties:
|
||||
prop bitvec: DisplayBitVec { get mut; set move; };
|
||||
prop offset: Offset { get; set; };
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
use crate::{
|
||||
commands::{wrap_command, wrap_origin_accessors},
|
||||
macros::wrap,
|
||||
};
|
||||
use crate::macros::wrap;
|
||||
use servicepoint::{BrightnessGrid, BrightnessGridCommand, Origin};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_command!(BrightnessGrid);
|
||||
wrap_origin_accessors!(BrightnessGridCommand);
|
||||
|
||||
wrap!(
|
||||
BrightnessGridCommand {
|
||||
derives: crate::commands::derive_command[BrightnessGrid], crate::commands::derive_origin_accessors;
|
||||
properties:
|
||||
prop grid: BrightnessGrid { get mut; set move; };
|
||||
functions:
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
use crate::commands::wrap_command;
|
||||
use servicepoint::{ClearCommand, FadeOutCommand, HardResetCommand};
|
||||
|
||||
macro_rules! wrap_cc_only {
|
||||
($(#[$meta:meta])* $command:ident) => {
|
||||
::paste::paste!{
|
||||
wrap_command!($command);
|
||||
|
||||
$crate::macros::wrap!{
|
||||
[< $command Command >] {
|
||||
derives: $crate::commands::derive_command[$command];
|
||||
functions:
|
||||
$(#[$meta])*
|
||||
///
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
use crate::{
|
||||
commands::{wrap_command, wrap_origin_accessors},
|
||||
macros::wrap,
|
||||
};
|
||||
use crate::macros::wrap;
|
||||
use servicepoint::{CharGrid, CharGridCommand, Origin};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_command!(CharGrid);
|
||||
wrap_origin_accessors!(CharGridCommand);
|
||||
|
||||
wrap!(
|
||||
CharGridCommand {
|
||||
derives: crate::commands::derive_command[CharGrid], crate::commands::derive_origin_accessors;
|
||||
properties:
|
||||
prop grid: CharGrid { get mut; set move; };
|
||||
functions:
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
use crate::{
|
||||
commands::{wrap_command, wrap_origin_accessors},
|
||||
macros::wrap,
|
||||
};
|
||||
use crate::macros::wrap;
|
||||
use servicepoint::{Cp437Grid, Cp437GridCommand, Origin};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_command!(Cp437Grid);
|
||||
wrap_origin_accessors!(Cp437GridCommand);
|
||||
|
||||
wrap!(
|
||||
Cp437GridCommand {
|
||||
derives: crate::commands::derive_command[Cp437Grid], crate::commands::derive_origin_accessors;
|
||||
properties:
|
||||
prop grid: Cp437Grid { get mut; set move; };
|
||||
functions:
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
use crate::{commands::wrap_command, macros::wrap};
|
||||
use crate::macros::wrap;
|
||||
use servicepoint::{Brightness, GlobalBrightnessCommand};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_command!(GlobalBrightness);
|
||||
|
||||
wrap!(
|
||||
GlobalBrightnessCommand {
|
||||
derives: crate::commands::derive_command[GlobalBrightness];
|
||||
properties:
|
||||
prop brightness: Brightness { get; set; };
|
||||
functions:
|
||||
|
|
|
@ -14,8 +14,8 @@ pub use char_grid_command::*;
|
|||
pub use cp437_grid_command::*;
|
||||
pub use generic_command::*;
|
||||
|
||||
macro_rules! wrap_origin_accessors {
|
||||
( $object_type:ident ) => {
|
||||
macro_rules! derive_origin_accessors {
|
||||
($object_type:ident) => {
|
||||
::paste::paste! {
|
||||
$crate::macros::wrap_methods!($object_type;
|
||||
#[doc = " Reads the origin field of the [`" $object_type "`]."]
|
||||
|
@ -70,21 +70,16 @@ macro_rules! derive_command_into_packet {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! wrap_command {
|
||||
($command:ident, $object_type:ident) => {
|
||||
macro_rules! derive_command {
|
||||
($object_type:ident, $command:ident) => {
|
||||
$crate::macros::derive_clone!($object_type);
|
||||
$crate::macros::derive_free!($object_type);
|
||||
$crate::commands::derive_command_from!($command);
|
||||
$crate::commands::derive_command_into_packet!($object_type);
|
||||
};
|
||||
($command:ident) => {
|
||||
::paste::paste! {
|
||||
$crate::commands::wrap_command!($command, [< $command Command >]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use {
|
||||
derive_command_from, derive_command_into_packet, wrap_command,
|
||||
wrap_origin_accessors,
|
||||
derive_command, derive_command_from, derive_command_into_packet,
|
||||
derive_origin_accessors,
|
||||
};
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
use crate::{
|
||||
containers::{wrap_grid, ByteSlice},
|
||||
macros::wrap,
|
||||
};
|
||||
use crate::{containers::ByteSlice, macros::wrap};
|
||||
use servicepoint::{
|
||||
Bitmap, BitmapCommand, CompressionCode, DataRef, DisplayBitVec, Grid,
|
||||
Origin, Packet,
|
||||
};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_grid!(Bitmap, bool);
|
||||
|
||||
wrap! {
|
||||
Bitmap {
|
||||
derives: crate::containers::derive_container, crate::containers::derive_grid[bool];
|
||||
functions:
|
||||
/// Creates a new [Bitmap] with the specified dimensions.
|
||||
///
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
use crate::{
|
||||
containers::{wrap_container, ByteSlice},
|
||||
macros::wrap,
|
||||
};
|
||||
use crate::{containers::ByteSlice, macros::wrap};
|
||||
use servicepoint::{
|
||||
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Packet,
|
||||
};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_container!(DisplayBitVec);
|
||||
|
||||
wrap! {
|
||||
DisplayBitVec {
|
||||
derives: crate::containers::derive_container;
|
||||
functions:
|
||||
/// Creates a new [DisplayBitVec] instance.
|
||||
///
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
use crate::{
|
||||
containers::{wrap_grid, ByteSlice},
|
||||
macros::wrap,
|
||||
};
|
||||
use crate::{containers::ByteSlice, macros::wrap};
|
||||
use servicepoint::{
|
||||
Brightness, BrightnessGrid, BrightnessGridCommand, ByteGrid, DataRef, Grid,
|
||||
Origin, Packet,
|
||||
};
|
||||
use std::{mem::transmute, ptr::NonNull};
|
||||
|
||||
wrap_grid!(BrightnessGrid, Brightness);
|
||||
|
||||
wrap! {
|
||||
BrightnessGrid {
|
||||
derives: crate::containers::derive_container, crate::containers::derive_grid[Brightness];
|
||||
functions:
|
||||
/// Creates a new [BrightnessGrid] with the specified dimensions.
|
||||
///
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
use crate::{
|
||||
containers::{derive_get_width_height, wrap_container, ByteSlice},
|
||||
macros::wrap,
|
||||
};
|
||||
use crate::{containers::ByteSlice, macros::wrap};
|
||||
use servicepoint::{CharGrid, CharGridCommand, Grid, Origin, Packet};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_container!(CharGrid);
|
||||
derive_get_width_height!(CharGrid);
|
||||
|
||||
wrap! {
|
||||
CharGrid {
|
||||
derives: crate::containers::derive_container, crate::containers::derive_get_width_height;
|
||||
functions:
|
||||
/// Creates a new [CharGrid] with the specified dimensions.
|
||||
///
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
use crate::{
|
||||
containers::{wrap_grid, ByteSlice},
|
||||
macros::wrap,
|
||||
};
|
||||
use crate::{containers::ByteSlice, macros::wrap};
|
||||
use servicepoint::{
|
||||
Cp437Grid, Cp437GridCommand, DataRef, Grid, Origin, Packet,
|
||||
};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_grid!(Cp437Grid, u8);
|
||||
|
||||
wrap! {
|
||||
Cp437Grid {
|
||||
derives: crate::containers::derive_container, crate::containers::derive_grid[u8];
|
||||
functions:
|
||||
/// Creates a new [Cp437Grid] with the specified dimensions.
|
||||
///
|
||||
|
|
|
@ -12,7 +12,7 @@ pub use byte_slice::*;
|
|||
pub use char_grid::*;
|
||||
pub use cp437_grid::*;
|
||||
|
||||
macro_rules! wrap_container {
|
||||
macro_rules! derive_container {
|
||||
($object_type:ident) => {
|
||||
$crate::macros::derive_clone!($object_type);
|
||||
$crate::macros::derive_free!($object_type);
|
||||
|
@ -31,9 +31,8 @@ macro_rules! derive_get_width_height {
|
|||
};
|
||||
}
|
||||
|
||||
macro_rules! wrap_grid {
|
||||
macro_rules! derive_grid {
|
||||
($object_type:ident, $value_type:ident) => {
|
||||
$crate::containers::wrap_container!($object_type);
|
||||
$crate::containers::derive_get_width_height!($object_type);
|
||||
$crate::macros::wrap_methods! {$object_type;
|
||||
/// Gets the current value at the specified position.
|
||||
|
@ -69,7 +68,7 @@ macro_rules! wrap_grid {
|
|||
};
|
||||
}
|
||||
|
||||
pub(crate) use {derive_get_width_height, wrap_container, wrap_grid};
|
||||
pub(crate) use {derive_container, derive_get_width_height, derive_grid};
|
||||
|
||||
mod _hidden {
|
||||
/// This is a type only used by cbindgen to have a type for pointers.
|
||||
|
|
|
@ -1,27 +1,23 @@
|
|||
macro_rules! derive_free {
|
||||
($typ:ident) => {
|
||||
::paste::paste! {
|
||||
$crate::macros::wrap_method!($typ;
|
||||
#[doc = "Deallocates a [`" $typ "`] instance."]
|
||||
($object_type:ident) => {
|
||||
$crate::macros::wrap_method!($object_type;
|
||||
#[doc = concat!("Deallocates a [`", stringify!($object_type), "`] instance.")]
|
||||
#[allow(dropping_copy_types)]
|
||||
fn free(move instance) {
|
||||
::std::mem::drop(instance)
|
||||
};
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! derive_clone {
|
||||
($object_type:ident) => {
|
||||
::paste::paste! {
|
||||
$crate::macros::wrap_method!($object_type;
|
||||
#[doc = "Clones a [`" $object_type "`] instance."]
|
||||
#[doc = concat!("Clones a [`", stringify!($object_type), "`] instance.")]
|
||||
fn clone(ref instance) -> move ::core::ptr::NonNull<$object_type> {
|
||||
instance.clone()
|
||||
};
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -266,6 +262,12 @@ macro_rules! wrap_functions {
|
|||
macro_rules! wrap {
|
||||
(
|
||||
$object_type:ident {
|
||||
$(
|
||||
derives:
|
||||
$(
|
||||
$derive:path $( [ $( $derive_arg:tt ),+ ] )?
|
||||
),+;
|
||||
)?
|
||||
$(
|
||||
properties:
|
||||
$(
|
||||
|
@ -292,6 +294,9 @@ macro_rules! wrap {
|
|||
)?
|
||||
}
|
||||
) => {
|
||||
$($(
|
||||
$derive!($object_type $(, $($derive_arg),+)?);
|
||||
)+)?
|
||||
$($(
|
||||
$crate::macros::wrap_fields!($object_type;
|
||||
prop $prop_name : $prop_type { $($accessor $($modifier)?;)+ };
|
||||
|
|
Loading…
Reference in a new issue