generic wrap
This commit is contained in:
parent
5beea6151a
commit
c65b735f57
16 changed files with 828 additions and 795 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::{wrap_grid, ByteSlice},
|
||||
macros::{wrap, wrap_functions},
|
||||
macros::wrap,
|
||||
};
|
||||
use servicepoint::{
|
||||
Bitmap, BitmapCommand, CompressionCode, DataRef, DisplayBitVec, Grid,
|
||||
|
@ -10,91 +10,93 @@ use std::ptr::NonNull;
|
|||
|
||||
wrap_grid!(Bitmap, bool);
|
||||
|
||||
wrap_functions!(associate Bitmap;
|
||||
/// Creates a new [Bitmap] with the specified dimensions.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `width`: size in pixels in x-direction
|
||||
/// - `height`: size in pixels in y-direction
|
||||
///
|
||||
/// returns: [Bitmap] initialized to all pixels off, or NULL in case of an error.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// In the following cases, this function will return NULL:
|
||||
///
|
||||
/// - when the width is not dividable by 8
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```C
|
||||
/// Cp437Grid grid = sp_bitmap_new(8, 3);
|
||||
/// sp_bitmap_fill(grid, true);
|
||||
/// sp_bitmap_set(grid, 0, 0, false);
|
||||
/// sp_bitmap_free(grid);
|
||||
/// ```
|
||||
fn new(width: val usize, height: val usize) -> move_some *mut Bitmap {
|
||||
Bitmap::new(width, height)
|
||||
};
|
||||
wrap! {
|
||||
Bitmap {
|
||||
functions:
|
||||
/// Creates a new [Bitmap] with the specified dimensions.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `width`: size in pixels in x-direction
|
||||
/// - `height`: size in pixels in y-direction
|
||||
///
|
||||
/// returns: [Bitmap] initialized to all pixels off, or NULL in case of an error.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// In the following cases, this function will return NULL:
|
||||
///
|
||||
/// - when the width is not dividable by 8
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```C
|
||||
/// Cp437Grid grid = sp_bitmap_new(8, 3);
|
||||
/// sp_bitmap_fill(grid, true);
|
||||
/// sp_bitmap_set(grid, 0, 0, false);
|
||||
/// sp_bitmap_free(grid);
|
||||
/// ```
|
||||
fn new(width: val usize, height: val usize) -> move_some *mut Bitmap {
|
||||
Bitmap::new(width, height)
|
||||
};
|
||||
|
||||
/// Creates a new [Bitmap] with a size matching the screen.
|
||||
///
|
||||
/// returns: [Bitmap] initialized to all pixels off.
|
||||
fn new_max_sized() -> move NonNull<Bitmap> {
|
||||
Bitmap::max_sized()
|
||||
};
|
||||
/// Creates a new [Bitmap] with a size matching the screen.
|
||||
///
|
||||
/// returns: [Bitmap] initialized to all pixels off.
|
||||
fn new_max_sized() -> move NonNull<Bitmap> {
|
||||
Bitmap::max_sized()
|
||||
};
|
||||
|
||||
/// Loads a [Bitmap] with the specified dimensions from the provided data.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `width`: size in pixels in x-direction
|
||||
/// - `height`: size in pixels in y-direction
|
||||
///
|
||||
/// returns: [Bitmap] that contains a copy of the provided data, or NULL in case of an error.
|
||||
fn load(
|
||||
width: val usize,
|
||||
height: val usize,
|
||||
data: slice ByteSlice,
|
||||
) -> move_ok *mut Bitmap {
|
||||
Bitmap::load(width, height, data)
|
||||
};
|
||||
/// Loads a [Bitmap] with the specified dimensions from the provided data.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `width`: size in pixels in x-direction
|
||||
/// - `height`: size in pixels in y-direction
|
||||
///
|
||||
/// returns: [Bitmap] that contains a copy of the provided data, or NULL in case of an error.
|
||||
fn load(
|
||||
width: val usize,
|
||||
height: val usize,
|
||||
data: slice ByteSlice,
|
||||
) -> move_ok *mut Bitmap {
|
||||
Bitmap::load(width, height, data)
|
||||
};
|
||||
|
||||
/// Tries to convert the BitVec to a Bitmap.
|
||||
///
|
||||
/// The provided BitVec gets consumed.
|
||||
///
|
||||
/// Returns NULL in case of error.
|
||||
fn from_bitvec(
|
||||
width: val usize,
|
||||
bitvec: move NonNull<DisplayBitVec>,
|
||||
) -> move_ok *mut Bitmap {
|
||||
Bitmap::from_bitvec(width, bitvec)
|
||||
};
|
||||
);
|
||||
/// Tries to convert the BitVec to a Bitmap.
|
||||
///
|
||||
/// The provided BitVec gets consumed.
|
||||
///
|
||||
/// Returns NULL in case of error.
|
||||
fn from_bitvec(
|
||||
width: val usize,
|
||||
bitvec: move NonNull<DisplayBitVec>,
|
||||
) -> move_ok *mut Bitmap {
|
||||
Bitmap::from_bitvec(width, bitvec)
|
||||
};
|
||||
|
||||
wrap!(Bitmap;
|
||||
/// Consumes the Bitmap and returns the contained BitVec.
|
||||
method into_bitvec(move bitmap) -> move NonNull<DisplayBitVec> {
|
||||
bitmap.into()
|
||||
};
|
||||
methods:
|
||||
/// Consumes the Bitmap and returns the contained BitVec.
|
||||
fn into_bitvec(move bitmap) -> move NonNull<DisplayBitVec> {
|
||||
bitmap.into()
|
||||
};
|
||||
|
||||
/// Creates a [BitmapCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
/// The provided [Bitmap] gets consumed.
|
||||
///
|
||||
/// Returns NULL in case of an error.
|
||||
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),
|
||||
compression,
|
||||
})
|
||||
};
|
||||
/// Creates a [BitmapCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
/// 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 {
|
||||
Packet::try_from(BitmapCommand {
|
||||
bitmap,
|
||||
origin: Origin::new(x, y),
|
||||
compression,
|
||||
})
|
||||
};
|
||||
|
||||
/// Gets an unsafe reference to the data of the [Bitmap] instance.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the bitmap.
|
||||
method data_ref_mut(mut instance) -> slice ByteSlice;
|
||||
);
|
||||
/// 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::{wrap_container, ByteSlice},
|
||||
macros::{wrap, wrap_functions},
|
||||
macros::wrap,
|
||||
};
|
||||
use servicepoint::{
|
||||
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Packet,
|
||||
|
@ -9,93 +9,95 @@ use std::ptr::NonNull;
|
|||
|
||||
wrap_container!(DisplayBitVec);
|
||||
|
||||
wrap_functions!(associate DisplayBitVec;
|
||||
/// Creates a new [DisplayBitVec] instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `size`: size in bits.
|
||||
///
|
||||
/// returns: [DisplayBitVec] with all bits set to false.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when `size` is not divisible by 8.
|
||||
fn new(size: val usize) -> move NonNull<DisplayBitVec> {
|
||||
DisplayBitVec::repeat(false, size)
|
||||
};
|
||||
wrap! {
|
||||
DisplayBitVec {
|
||||
functions:
|
||||
/// Creates a new [DisplayBitVec] instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `size`: size in bits.
|
||||
///
|
||||
/// returns: [DisplayBitVec] with all bits set to false.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when `size` is not divisible by 8.
|
||||
fn new(size: val usize) -> move NonNull<DisplayBitVec> {
|
||||
DisplayBitVec::repeat(false, size)
|
||||
};
|
||||
|
||||
/// Interpret the data as a series of bits and load then into a new [DisplayBitVec] instance.
|
||||
///
|
||||
/// returns: [DisplayBitVec] instance containing data.
|
||||
fn load(data: slice ByteSlice) -> move NonNull<DisplayBitVec> {
|
||||
DisplayBitVec::from_slice(data)
|
||||
};
|
||||
);
|
||||
/// Interpret the data as a series of bits and load then into a new [DisplayBitVec] instance.
|
||||
///
|
||||
/// returns: [DisplayBitVec] instance containing data.
|
||||
fn load(data: slice ByteSlice) -> move NonNull<DisplayBitVec> {
|
||||
DisplayBitVec::from_slice(data)
|
||||
};
|
||||
|
||||
wrap!(DisplayBitVec;
|
||||
/// Creates a [BitVecCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
/// The provided [DisplayBitVec] gets consumed.
|
||||
///
|
||||
/// Returns NULL in case of an error.
|
||||
method try_into_packet(
|
||||
move bitvec,
|
||||
offset: val usize,
|
||||
operation: val BinaryOperation,
|
||||
compression: val CompressionCode
|
||||
) -> move_ok *mut Packet {
|
||||
Packet::try_from(BitVecCommand {
|
||||
bitvec,
|
||||
offset,
|
||||
operation,
|
||||
compression,
|
||||
})
|
||||
};
|
||||
methods:
|
||||
/// 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(
|
||||
move bitvec,
|
||||
offset: val usize,
|
||||
operation: val BinaryOperation,
|
||||
compression: val CompressionCode
|
||||
) -> move_ok *mut Packet {
|
||||
Packet::try_from(BitVecCommand {
|
||||
bitvec,
|
||||
offset,
|
||||
operation,
|
||||
compression,
|
||||
})
|
||||
};
|
||||
|
||||
/// Gets the value of a bit.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bit_vec`: instance to read from
|
||||
/// - `index`: the bit index to read
|
||||
///
|
||||
/// returns: value of the bit
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when accessing `index` out of bounds
|
||||
method get(ref instance, index: val usize) -> val bool {
|
||||
instance.get(index).map(|x| *x).unwrap_or(false)
|
||||
};
|
||||
/// Gets the value of a bit.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bit_vec`: instance to read from
|
||||
/// - `index`: the bit index to read
|
||||
///
|
||||
/// returns: value of the bit
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when accessing `index` out of bounds
|
||||
fn get(ref instance, index: val usize) -> val bool {
|
||||
instance.get(index).map(|x| *x).unwrap_or(false)
|
||||
};
|
||||
|
||||
/// Sets the value of a bit.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `index`: the bit index to edit
|
||||
/// - `value`: the value to set the bit to
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when accessing `index` out of bounds
|
||||
method set(mut instance, index: val usize, value: val bool);
|
||||
/// Sets the value of a bit.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `index`: the bit index to edit
|
||||
/// - `value`: the value to set the bit to
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when accessing `index` out of bounds
|
||||
fn set(mut instance, index: val usize, value: val bool);
|
||||
|
||||
/// Sets the value of all bits.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `value`: the value to set all bits to
|
||||
method fill(mut instance, 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);
|
||||
|
||||
/// Gets the length in bits.
|
||||
method len(ref instance) -> val usize;
|
||||
/// Gets the length in bits.
|
||||
fn len(ref instance) -> val usize;
|
||||
|
||||
/// Returns true if length is 0.
|
||||
method is_empty(ref instance) -> val bool;
|
||||
/// Returns true if length is 0.
|
||||
fn 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.
|
||||
method as_raw_mut_slice(mut instance) -> slice ByteSlice;
|
||||
);
|
||||
/// 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::{wrap_grid, ByteSlice},
|
||||
macros::{wrap, wrap_functions},
|
||||
macros::wrap,
|
||||
};
|
||||
use servicepoint::{
|
||||
Brightness, BrightnessGrid, BrightnessGridCommand, ByteGrid, DataRef, Grid,
|
||||
|
@ -10,66 +10,68 @@ use std::{mem::transmute, ptr::NonNull};
|
|||
|
||||
wrap_grid!(BrightnessGrid, Brightness);
|
||||
|
||||
wrap_functions!(associate BrightnessGrid;
|
||||
/// Creates a new [BrightnessGrid] with the specified dimensions.
|
||||
///
|
||||
/// returns: [BrightnessGrid] initialized to 0.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```C
|
||||
/// UdpSocket *connection = sp_udp_open("127.0.0.1:2342");
|
||||
/// if (connection == NULL)
|
||||
/// return 1;
|
||||
///
|
||||
/// 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);
|
||||
/// sp_udp_free(connection);
|
||||
/// ```
|
||||
fn new(width: val usize, height: val usize) -> move NonNull<BrightnessGrid> {
|
||||
BrightnessGrid::new(width, height)
|
||||
};
|
||||
wrap! {
|
||||
BrightnessGrid {
|
||||
functions:
|
||||
/// Creates a new [BrightnessGrid] with the specified dimensions.
|
||||
///
|
||||
/// returns: [BrightnessGrid] initialized to 0.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```C
|
||||
/// UdpSocket *connection = sp_udp_open("127.0.0.1:2342");
|
||||
/// if (connection == NULL)
|
||||
/// return 1;
|
||||
///
|
||||
/// 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);
|
||||
/// sp_udp_free(connection);
|
||||
/// ```
|
||||
fn new(width: val usize, height: val usize) -> move NonNull<BrightnessGrid> {
|
||||
BrightnessGrid::new(width, height)
|
||||
};
|
||||
|
||||
/// Loads a [BrightnessGrid] with the specified dimensions from the provided data.
|
||||
///
|
||||
/// Any out of range values will be set to [Brightness::MAX] or [Brightness::MIN].
|
||||
///
|
||||
/// returns: new [BrightnessGrid] instance, or NULL in case of an error.
|
||||
fn load(
|
||||
width: val usize,
|
||||
height: val usize,
|
||||
data: slice ByteSlice,
|
||||
) -> move_some *mut BrightnessGrid {
|
||||
ByteGrid::load(width, height, data)
|
||||
.map(move |grid| grid.map(Brightness::saturating_from))
|
||||
};
|
||||
);
|
||||
/// Loads a [BrightnessGrid] with the specified dimensions from the provided data.
|
||||
///
|
||||
/// Any out of range values will be set to [Brightness::MAX] or [Brightness::MIN].
|
||||
///
|
||||
/// returns: new [BrightnessGrid] instance, or NULL in case of an error.
|
||||
fn load(
|
||||
width: val usize,
|
||||
height: val usize,
|
||||
data: slice ByteSlice,
|
||||
) -> move_some *mut BrightnessGrid {
|
||||
ByteGrid::load(width, height, data)
|
||||
.map(move |grid| grid.map(Brightness::saturating_from))
|
||||
};
|
||||
|
||||
wrap!(BrightnessGrid;
|
||||
/// Creates a [BrightnessGridCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
/// The provided [BrightnessGrid] gets consumed.
|
||||
///
|
||||
/// Returns NULL in case of an error.
|
||||
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),
|
||||
})
|
||||
};
|
||||
methods:
|
||||
/// 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 {
|
||||
Packet::try_from(BrightnessGridCommand {
|
||||
grid,
|
||||
origin: Origin::new(x, y),
|
||||
})
|
||||
};
|
||||
|
||||
/// Gets an unsafe reference to the data of the instance.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the grid.
|
||||
method data_ref_mut(mut instance) -> slice ByteSlice {
|
||||
//noinspection RsAssertEqual
|
||||
const _: () = assert!(size_of::<Brightness>() == 1);
|
||||
/// 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 {
|
||||
//noinspection RsAssertEqual
|
||||
const _: () = assert!(size_of::<Brightness>() == 1);
|
||||
|
||||
let br_slice = instance.data_ref_mut();
|
||||
unsafe {
|
||||
transmute::<&mut [Brightness], &mut [u8]>(br_slice)
|
||||
}
|
||||
};
|
||||
);
|
||||
let br_slice = instance.data_ref_mut();
|
||||
unsafe {
|
||||
transmute::<&mut [Brightness], &mut [u8]>(br_slice)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::{derive_get_width_height, wrap_container, ByteSlice},
|
||||
macros::{wrap, wrap_functions},
|
||||
macros::wrap,
|
||||
};
|
||||
use servicepoint::{CharGrid, CharGridCommand, Grid, Origin, Packet};
|
||||
use std::ptr::NonNull;
|
||||
|
@ -8,81 +8,82 @@ use std::ptr::NonNull;
|
|||
wrap_container!(CharGrid);
|
||||
derive_get_width_height!(CharGrid);
|
||||
|
||||
wrap_functions!(associate CharGrid;
|
||||
/// Creates a new [CharGrid] with the specified dimensions.
|
||||
///
|
||||
/// returns: [CharGrid] initialized to 0.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```C
|
||||
/// CharGrid grid = sp_char_grid_new(4, 3);
|
||||
/// sp_char_grid_fill(grid, '?');
|
||||
/// sp_char_grid_set(grid, 0, 0, '!');
|
||||
/// sp_char_grid_free(grid);
|
||||
/// ```
|
||||
fn new(width: val usize, height: val usize) -> move NonNull<CharGrid> {
|
||||
CharGrid::new(width, height)
|
||||
};
|
||||
wrap! {
|
||||
CharGrid {
|
||||
functions:
|
||||
/// Creates a new [CharGrid] with the specified dimensions.
|
||||
///
|
||||
/// returns: [CharGrid] initialized to 0.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```C
|
||||
/// CharGrid grid = sp_char_grid_new(4, 3);
|
||||
/// sp_char_grid_fill(grid, '?');
|
||||
/// sp_char_grid_set(grid, 0, 0, '!');
|
||||
/// sp_char_grid_free(grid);
|
||||
/// ```
|
||||
fn new(width: val usize, height: val usize) -> move NonNull<CharGrid> {
|
||||
CharGrid::new(width, height)
|
||||
};
|
||||
|
||||
/// Loads a [CharGrid] with the specified dimensions from the provided data.
|
||||
///
|
||||
/// returns: new CharGrid or NULL in case of an error
|
||||
fn load(width: val usize, height: val usize, data: slice ByteSlice) -> move_ok *mut CharGrid {
|
||||
CharGrid::load_utf8(width, height, data.to_vec())
|
||||
};
|
||||
);
|
||||
/// Loads a [CharGrid] with the specified dimensions from the provided data.
|
||||
///
|
||||
/// returns: new CharGrid or NULL in case of an error
|
||||
fn load(width: val usize, height: val usize, data: slice ByteSlice) -> move_ok *mut CharGrid {
|
||||
CharGrid::load_utf8(width, height, data.to_vec())
|
||||
};
|
||||
methods:
|
||||
/// Returns the current value at the specified position.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `x` and `y`: position of the cell to read
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when accessing `x` or `y` out of bounds
|
||||
fn get(ref instance, x: val usize, y: val usize) -> val u32 {
|
||||
instance.get(x, y) as u32
|
||||
};
|
||||
|
||||
wrap!(CharGrid;
|
||||
/// Returns the current value at the specified position.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `x` and `y`: position of the cell to read
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when accessing `x` or `y` out of bounds
|
||||
method get(ref instance, x: val usize, y: val usize) -> val u32 {
|
||||
instance.get(x, y) as u32
|
||||
};
|
||||
/// Sets the value of the specified position in the grid.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `x` and `y`: position of the cell
|
||||
/// - `value`: the value to write to the cell
|
||||
///
|
||||
/// returns: old value of the cell
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - 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) {
|
||||
instance.set(x, y, char::from_u32(value).unwrap())
|
||||
};
|
||||
|
||||
/// Sets the value of the specified position in the grid.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `x` and `y`: position of the cell
|
||||
/// - `value`: the value to write to the cell
|
||||
///
|
||||
/// returns: old value of the cell
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when accessing `x` or `y` out of bounds
|
||||
/// - when providing values that cannot be converted to Rust's `char`.
|
||||
method set(mut instance, x: val usize, y: val usize, value: val u32) {
|
||||
instance.set(x, y, char::from_u32(value).unwrap())
|
||||
};
|
||||
/// Sets the value of all cells in the grid.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `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) {
|
||||
instance.fill(char::from_u32(value).unwrap())
|
||||
};
|
||||
|
||||
/// Sets the value of all cells in the grid.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `value`: the value to set all cells to
|
||||
/// - when providing values that cannot be converted to Rust's `char`.
|
||||
method fill(mut instance, value: val u32) {
|
||||
instance.fill(char::from_u32(value).unwrap())
|
||||
};
|
||||
|
||||
/// Creates a [CharGridCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
/// The provided [CharGrid] gets consumed.
|
||||
///
|
||||
/// Returns NULL in case of an error.
|
||||
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),
|
||||
})
|
||||
};
|
||||
);
|
||||
/// Creates a [CharGridCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
/// 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 {
|
||||
Packet::try_from(CharGridCommand {
|
||||
grid,
|
||||
origin: Origin::new(x, y),
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::{wrap_grid, ByteSlice},
|
||||
macros::{wrap, wrap_functions},
|
||||
macros::wrap,
|
||||
};
|
||||
use servicepoint::{
|
||||
Cp437Grid, Cp437GridCommand, DataRef, Grid, Origin, Packet,
|
||||
|
@ -9,35 +9,37 @@ use std::ptr::NonNull;
|
|||
|
||||
wrap_grid!(Cp437Grid, u8);
|
||||
|
||||
wrap_functions!(associate Cp437Grid;
|
||||
/// Creates a new [Cp437Grid] with the specified dimensions.
|
||||
///
|
||||
/// returns: [Cp437Grid] initialized to 0.
|
||||
fn new(width: val usize, height: val usize) -> move NonNull<Cp437Grid> {
|
||||
Cp437Grid::new(width, height)
|
||||
};
|
||||
wrap! {
|
||||
Cp437Grid {
|
||||
functions:
|
||||
/// Creates a new [Cp437Grid] with the specified dimensions.
|
||||
///
|
||||
/// returns: [Cp437Grid] initialized to 0.
|
||||
fn new(width: val usize, height: val usize) -> move NonNull<Cp437Grid> {
|
||||
Cp437Grid::new(width, height)
|
||||
};
|
||||
|
||||
/// Loads a [Cp437Grid] with the specified dimensions from the provided data.
|
||||
fn load(width: val usize, height: val usize, data: slice ByteSlice) -> move_some *mut Cp437Grid {
|
||||
Cp437Grid::load(width, height, data)
|
||||
};
|
||||
);
|
||||
/// Loads a [Cp437Grid] with the specified dimensions from the provided data.
|
||||
fn load(width: val usize, height: val usize, data: slice ByteSlice) -> move_some *mut Cp437Grid {
|
||||
Cp437Grid::load(width, height, data)
|
||||
};
|
||||
|
||||
wrap!(Cp437Grid;
|
||||
/// Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
/// The provided [Cp437Grid] gets consumed.
|
||||
///
|
||||
/// Returns NULL in case of an error.
|
||||
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),
|
||||
})
|
||||
};
|
||||
methods:
|
||||
/// 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 {
|
||||
Packet::try_from(Cp437GridCommand {
|
||||
grid,
|
||||
origin: Origin::new(x, y),
|
||||
})
|
||||
};
|
||||
|
||||
/// Gets an unsafe reference to the data of the grid.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the instance.
|
||||
method data_ref_mut(mut instance) -> slice ByteSlice;
|
||||
);
|
||||
/// 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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue