wip generic wrap
This commit is contained in:
parent
82696b2d1a
commit
5beea6151a
15 changed files with 83 additions and 59 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::{wrap_grid, ByteSlice},
|
||||
macros::{wrap_functions, wrap_methods},
|
||||
macros::{wrap, wrap_functions},
|
||||
};
|
||||
use servicepoint::{
|
||||
Bitmap, BitmapCommand, CompressionCode, DataRef, DisplayBitVec, Grid,
|
||||
|
@ -74,9 +74,9 @@ wrap_functions!(associate Bitmap;
|
|||
};
|
||||
);
|
||||
|
||||
wrap_methods!(Bitmap;
|
||||
wrap!(Bitmap;
|
||||
/// Consumes the Bitmap and returns the contained BitVec.
|
||||
fn into_bitvec(move bitmap) -> move NonNull<DisplayBitVec> {
|
||||
method into_bitvec(move bitmap) -> move NonNull<DisplayBitVec> {
|
||||
bitmap.into()
|
||||
};
|
||||
|
||||
|
@ -85,7 +85,7 @@ wrap_methods!(Bitmap;
|
|||
/// The provided [Bitmap] gets consumed.
|
||||
///
|
||||
/// Returns NULL in case of an error.
|
||||
fn try_into_packet(move bitmap, x: val usize, y: val usize, compression: val CompressionCode) -> move_ok *mut Packet {
|
||||
method try_into_packet(move bitmap, x: val usize, y: val usize, compression: val CompressionCode) -> move_ok *mut Packet {
|
||||
Packet::try_from(BitmapCommand {
|
||||
bitmap,
|
||||
origin: Origin::new(x, y),
|
||||
|
@ -96,5 +96,5 @@ wrap_methods!(Bitmap;
|
|||
/// Gets an unsafe reference to the data of the [Bitmap] instance.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the bitmap.
|
||||
fn data_ref_mut(mut instance) -> slice ByteSlice;
|
||||
method data_ref_mut(mut instance) -> slice ByteSlice;
|
||||
);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::{wrap_container, ByteSlice},
|
||||
macros::{wrap_functions, wrap_methods},
|
||||
macros::{wrap, wrap_functions},
|
||||
};
|
||||
use servicepoint::{
|
||||
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Packet,
|
||||
|
@ -33,13 +33,13 @@ wrap_functions!(associate DisplayBitVec;
|
|||
};
|
||||
);
|
||||
|
||||
wrap_methods!(DisplayBitVec;
|
||||
wrap!(DisplayBitVec;
|
||||
/// Creates a [BitVecCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
/// The provided [DisplayBitVec] gets consumed.
|
||||
///
|
||||
/// Returns NULL in case of an error.
|
||||
fn try_into_packet(
|
||||
method try_into_packet(
|
||||
move bitvec,
|
||||
offset: val usize,
|
||||
operation: val BinaryOperation,
|
||||
|
@ -65,7 +65,7 @@ wrap_methods!(DisplayBitVec;
|
|||
/// # Panics
|
||||
///
|
||||
/// - when accessing `index` out of bounds
|
||||
fn get(ref instance, index: val usize) -> val bool {
|
||||
method get(ref instance, index: val usize) -> val bool {
|
||||
instance.get(index).map(|x| *x).unwrap_or(false)
|
||||
};
|
||||
|
||||
|
@ -79,23 +79,23 @@ wrap_methods!(DisplayBitVec;
|
|||
/// # Panics
|
||||
///
|
||||
/// - when accessing `index` out of bounds
|
||||
fn set(mut instance, index: val usize, value: val bool);
|
||||
method set(mut instance, index: val usize, value: val bool);
|
||||
|
||||
/// Sets the value of all bits.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `value`: the value to set all bits to
|
||||
fn fill(mut instance, value: val bool);
|
||||
method fill(mut instance, value: val bool);
|
||||
|
||||
/// Gets the length in bits.
|
||||
fn len(ref instance) -> val usize;
|
||||
method len(ref instance) -> val usize;
|
||||
|
||||
/// Returns true if length is 0.
|
||||
fn is_empty(ref instance) -> val bool;
|
||||
method is_empty(ref instance) -> val bool;
|
||||
|
||||
/// Gets an unsafe reference to the data of the [DisplayBitVec] instance.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the bitvec.
|
||||
fn as_raw_mut_slice(mut instance) -> slice ByteSlice;
|
||||
method as_raw_mut_slice(mut instance) -> slice ByteSlice;
|
||||
);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::{wrap_grid, ByteSlice},
|
||||
macros::{wrap_functions, wrap_methods},
|
||||
macros::{wrap, wrap_functions},
|
||||
};
|
||||
use servicepoint::{
|
||||
Brightness, BrightnessGrid, BrightnessGridCommand, ByteGrid, DataRef, Grid,
|
||||
|
@ -47,13 +47,13 @@ wrap_functions!(associate BrightnessGrid;
|
|||
};
|
||||
);
|
||||
|
||||
wrap_methods!(BrightnessGrid;
|
||||
wrap!(BrightnessGrid;
|
||||
/// Creates a [BrightnessGridCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
/// The provided [BrightnessGrid] gets consumed.
|
||||
///
|
||||
/// Returns NULL in case of an error.
|
||||
fn try_into_packet(move grid, x: val usize, y: val usize) -> move_ok *mut Packet {
|
||||
method try_into_packet(move grid, x: val usize, y: val usize) -> move_ok *mut Packet {
|
||||
Packet::try_from(BrightnessGridCommand {
|
||||
grid,
|
||||
origin: Origin::new(x, y),
|
||||
|
@ -63,7 +63,7 @@ wrap_methods!(BrightnessGrid;
|
|||
/// Gets an unsafe reference to the data of the instance.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the grid.
|
||||
fn data_ref_mut(mut instance) -> slice ByteSlice {
|
||||
method data_ref_mut(mut instance) -> slice ByteSlice {
|
||||
//noinspection RsAssertEqual
|
||||
const _: () = assert!(size_of::<Brightness>() == 1);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::{derive_get_width_height, wrap_container, ByteSlice},
|
||||
macros::{wrap_functions, wrap_methods},
|
||||
macros::{wrap, wrap_functions},
|
||||
};
|
||||
use servicepoint::{CharGrid, CharGridCommand, Grid, Origin, Packet};
|
||||
use std::ptr::NonNull;
|
||||
|
@ -33,8 +33,7 @@ wrap_functions!(associate CharGrid;
|
|||
};
|
||||
);
|
||||
|
||||
wrap_methods!(CharGrid;
|
||||
|
||||
wrap!(CharGrid;
|
||||
/// Returns the current value at the specified position.
|
||||
///
|
||||
/// # Arguments
|
||||
|
@ -44,7 +43,7 @@ wrap_methods!(CharGrid;
|
|||
/// # Panics
|
||||
///
|
||||
/// - when accessing `x` or `y` out of bounds
|
||||
fn get(ref instance, x: val usize, y: val usize) -> val u32 {
|
||||
method get(ref instance, x: val usize, y: val usize) -> val u32 {
|
||||
instance.get(x, y) as u32
|
||||
};
|
||||
|
||||
|
@ -61,7 +60,7 @@ wrap_methods!(CharGrid;
|
|||
///
|
||||
/// - when accessing `x` or `y` out of bounds
|
||||
/// - when providing values that cannot be converted to Rust's `char`.
|
||||
fn set(mut instance, x: val usize, y: val usize, value: val u32) {
|
||||
method set(mut instance, x: val usize, y: val usize, value: val u32) {
|
||||
instance.set(x, y, char::from_u32(value).unwrap())
|
||||
};
|
||||
|
||||
|
@ -71,7 +70,7 @@ wrap_methods!(CharGrid;
|
|||
///
|
||||
/// - `value`: the value to set all cells to
|
||||
/// - when providing values that cannot be converted to Rust's `char`.
|
||||
fn fill(mut instance, value: val u32) {
|
||||
method fill(mut instance, value: val u32) {
|
||||
instance.fill(char::from_u32(value).unwrap())
|
||||
};
|
||||
|
||||
|
@ -80,7 +79,7 @@ wrap_methods!(CharGrid;
|
|||
/// The provided [CharGrid] gets consumed.
|
||||
///
|
||||
/// Returns NULL in case of an error.
|
||||
fn try_into_packet(move grid, x: val usize, y: val usize) -> move_ok *mut Packet {
|
||||
method try_into_packet(move grid, x: val usize, y: val usize) -> move_ok *mut Packet {
|
||||
Packet::try_from(CharGridCommand {
|
||||
grid,
|
||||
origin: Origin::new(x, y),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::{wrap_grid, ByteSlice},
|
||||
macros::{wrap_functions, wrap_methods},
|
||||
macros::{wrap, wrap_functions},
|
||||
};
|
||||
use servicepoint::{
|
||||
Cp437Grid, Cp437GridCommand, DataRef, Grid, Origin, Packet,
|
||||
|
@ -23,13 +23,13 @@ wrap_functions!(associate Cp437Grid;
|
|||
};
|
||||
);
|
||||
|
||||
wrap_methods!(Cp437Grid;
|
||||
wrap!(Cp437Grid;
|
||||
/// Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
/// The provided [Cp437Grid] gets consumed.
|
||||
///
|
||||
/// Returns NULL in case of an error.
|
||||
fn try_into_packet(move grid, x: val usize, y: val usize) -> move_ok *mut Packet {
|
||||
method try_into_packet(move grid, x: val usize, y: val usize) -> move_ok *mut Packet {
|
||||
Packet::try_from(Cp437GridCommand {
|
||||
grid,
|
||||
origin: Origin::new(x, y),
|
||||
|
@ -39,5 +39,5 @@ wrap_methods!(Cp437Grid;
|
|||
/// Gets an unsafe reference to the data of the grid.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the instance.
|
||||
fn data_ref_mut(mut instance) -> slice ByteSlice;
|
||||
method data_ref_mut(mut instance) -> slice ByteSlice;
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue