wrap normal methods with macro
This commit is contained in:
parent
f524038625
commit
9756ef39b7
7 changed files with 477 additions and 591 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::ByteSlice,
|
||||
macros::{wrap_clone, wrap_free},
|
||||
macros::{wrap_clone, wrap_free, wrap_method},
|
||||
mem::{heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove},
|
||||
};
|
||||
use servicepoint::{
|
||||
|
@ -83,98 +83,67 @@ pub unsafe extern "C" fn sp_bitmap_from_bitvec(
|
|||
wrap_clone!(Bitmap, sp_bitmap);
|
||||
wrap_free!(Bitmap, sp_bitmap);
|
||||
|
||||
/// Gets the current value at the specified position in the [Bitmap].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bitmap`: instance to read from
|
||||
/// - `x` and `y`: position of the cell to read
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when accessing `x` or `y` out of bounds
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitmap_get(
|
||||
bitmap: NonNull<Bitmap>,
|
||||
x: usize,
|
||||
y: usize,
|
||||
) -> bool {
|
||||
unsafe { bitmap.as_ref().get(x, y) }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_bitmap :: Bitmap;
|
||||
/// Gets 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
|
||||
ref fn get(x: usize, y: usize) -> bool;
|
||||
);
|
||||
|
||||
/// Sets the value of the specified position in the [Bitmap].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bitmap`: instance to write to
|
||||
/// - `x` and `y`: position of the cell
|
||||
/// - `value`: the value to write to the cell
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when accessing `x` or `y` out of bounds
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitmap_set(
|
||||
bitmap: NonNull<Bitmap>,
|
||||
x: usize,
|
||||
y: usize,
|
||||
value: bool,
|
||||
) {
|
||||
unsafe { (*bitmap.as_ptr()).set(x, y, value) };
|
||||
}
|
||||
wrap_method!(
|
||||
sp_bitmap :: Bitmap;
|
||||
/// Sets the value of the specified position.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `x` and `y`: position of the cell
|
||||
/// - `value`: the value to write to the cell
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when accessing `x` or `y` out of bounds
|
||||
mut fn set(x: usize, y: usize, value: bool);
|
||||
);
|
||||
|
||||
/// Sets the state of all pixels in the [Bitmap].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bitmap`: instance to write to
|
||||
/// - `value`: the value to set all pixels to
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitmap_fill(bitmap: NonNull<Bitmap>, value: bool) {
|
||||
unsafe { (*bitmap.as_ptr()).fill(value) };
|
||||
}
|
||||
wrap_method!(
|
||||
sp_bitmap :: Bitmap;
|
||||
/// Sets the state of all pixels in the [Bitmap].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `value`: the value to set all pixels to
|
||||
mut fn fill(value: bool);
|
||||
);
|
||||
|
||||
/// Gets the width in pixels of the [Bitmap] instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bitmap`: instance to read from
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when `bitmap` is NULL
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller has to make sure that:
|
||||
///
|
||||
/// - `bitmap` points to a valid [Bitmap]
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitmap_width(bitmap: NonNull<Bitmap>) -> usize {
|
||||
unsafe { bitmap.as_ref().width() }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_bitmap :: Bitmap;
|
||||
/// Gets the width in pixels.
|
||||
ref fn width() -> usize;
|
||||
);
|
||||
|
||||
/// Gets the height in pixels of the [Bitmap] instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bitmap`: instance to read from
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitmap_height(bitmap: NonNull<Bitmap>) -> usize {
|
||||
unsafe { bitmap.as_ref().height() }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_bitmap :: Bitmap;
|
||||
/// Gets the height in pixels.
|
||||
ref fn height() -> usize;
|
||||
);
|
||||
|
||||
/// Gets an unsafe reference to the data of the [Bitmap] instance.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the bitmap.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitmap_unsafe_data_ref(
|
||||
mut bitmap: NonNull<Bitmap>,
|
||||
) -> ByteSlice {
|
||||
unsafe { ByteSlice::from_slice(bitmap.as_mut().data_ref_mut()) }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_bitmap :: Bitmap;
|
||||
/// Gets an unsafe reference to the data of the [Bitmap] instance.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the bitmap.
|
||||
mut fn data_ref_mut() -> ByteSlice;
|
||||
|slice| unsafe { ByteSlice::from_slice(slice) };
|
||||
);
|
||||
|
||||
/// Consumes the Bitmap and returns the contained BitVec
|
||||
/// Consumes the Bitmap and returns the contained BitVec.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitmap_into_bitvec(
|
||||
bitmap: NonNull<Bitmap>,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::ByteSlice,
|
||||
macros::{wrap_clone, wrap_free},
|
||||
macros::{wrap_clone, wrap_free, wrap_method},
|
||||
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
|
||||
};
|
||||
use servicepoint::{
|
||||
|
@ -38,97 +38,69 @@ pub unsafe extern "C" fn sp_bitvec_load(
|
|||
wrap_clone!(DisplayBitVec, sp_bitvec);
|
||||
wrap_free!(DisplayBitVec, sp_bitvec);
|
||||
|
||||
/// Gets the value of a bit from the [DisplayBitVec].
|
||||
///
|
||||
/// # 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
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitvec_get(
|
||||
bit_vec: NonNull<DisplayBitVec>,
|
||||
index: usize,
|
||||
) -> bool {
|
||||
unsafe { *bit_vec.as_ref().get(index).unwrap() }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_bitvec :: DisplayBitVec;
|
||||
/// 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
|
||||
ref fn get(index: usize) -> bool;
|
||||
|result| result.map(|x| *x).unwrap_or(false);
|
||||
);
|
||||
|
||||
/// Sets the value of a bit in the [DisplayBitVec].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bit_vec`: instance to write to
|
||||
/// - `index`: the bit index to edit
|
||||
/// - `value`: the value to set the bit to
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when accessing `index` out of bounds
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitvec_set(
|
||||
bit_vec: NonNull<DisplayBitVec>,
|
||||
index: usize,
|
||||
value: bool,
|
||||
) {
|
||||
unsafe { (*bit_vec.as_ptr()).set(index, value) }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_bitvec :: DisplayBitVec;
|
||||
/// 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
|
||||
mut fn set(index: usize, value: bool);
|
||||
);
|
||||
|
||||
/// Sets the value of all bits in the [DisplayBitVec].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bit_vec`: instance to write to
|
||||
/// - `value`: the value to set all bits to
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitvec_fill(
|
||||
bit_vec: NonNull<DisplayBitVec>,
|
||||
value: bool,
|
||||
) {
|
||||
unsafe { (*bit_vec.as_ptr()).fill(value) }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_bitvec :: DisplayBitVec;
|
||||
/// Sets the value of all bits.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `value`: the value to set all bits to
|
||||
mut fn fill(value: bool);
|
||||
);
|
||||
|
||||
/// Gets the length of the [DisplayBitVec] in bits.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bit_vec`: instance to write to
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitvec_len(
|
||||
bit_vec: NonNull<DisplayBitVec>,
|
||||
) -> usize {
|
||||
unsafe { bit_vec.as_ref().len() }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_bitvec :: DisplayBitVec;
|
||||
/// Gets the length in bits.
|
||||
ref fn len() -> usize;
|
||||
);
|
||||
|
||||
/// Returns true if length is 0.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bit_vec`: instance to write to
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitvec_is_empty(
|
||||
bit_vec: NonNull<DisplayBitVec>,
|
||||
) -> bool {
|
||||
unsafe { bit_vec.as_ref().is_empty() }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_bitvec :: DisplayBitVec;
|
||||
/// Returns true if length is 0.
|
||||
ref fn is_empty() -> bool;
|
||||
);
|
||||
|
||||
/// Gets an unsafe reference to the data of the [DisplayBitVec] instance.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the bitvec.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `bit_vec`: instance to write to
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitvec_unsafe_data_ref(
|
||||
bit_vec: NonNull<DisplayBitVec>,
|
||||
) -> ByteSlice {
|
||||
unsafe { ByteSlice::from_slice((*bit_vec.as_ptr()).as_raw_mut_slice()) }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_bitvec :: DisplayBitVec;
|
||||
/// Gets an unsafe reference to the data of the [DisplayBitVec] instance.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the bitvec.
|
||||
mut fn as_raw_mut_slice() -> ByteSlice;
|
||||
|slice| unsafe { ByteSlice::from_slice(slice) };
|
||||
);
|
||||
|
||||
/// Creates a [BitVecCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::ByteSlice,
|
||||
macros::{wrap_clone, wrap_free},
|
||||
macros::{wrap_clone, wrap_free, wrap_method},
|
||||
mem::{heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove},
|
||||
};
|
||||
use servicepoint::{
|
||||
|
@ -55,112 +55,73 @@ pub unsafe extern "C" fn sp_brightness_grid_load(
|
|||
wrap_clone!(BrightnessGrid, sp_brightness_grid);
|
||||
wrap_free!(BrightnessGrid, sp_brightness_grid);
|
||||
|
||||
/// Gets the current value at the specified position.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `brightness_grid`: instance to read from
|
||||
/// - `x` and `y`: position of the cell to read
|
||||
///
|
||||
/// returns: value at position
|
||||
///
|
||||
/// # Panics
|
||||
/// - When accessing `x` or `y` out of bounds.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_get(
|
||||
brightness_grid: NonNull<BrightnessGrid>,
|
||||
x: usize,
|
||||
y: usize,
|
||||
) -> Brightness {
|
||||
unsafe { brightness_grid.as_ref().get(x, y) }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_brightness_grid :: BrightnessGrid;
|
||||
/// Gets the current value at the specified position.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `x` and `y`: position of the cell to read
|
||||
///
|
||||
/// returns: value at position
|
||||
///
|
||||
/// # Panics
|
||||
/// - When accessing `x` or `y` out of bounds.
|
||||
ref fn get(x: usize, y: usize) -> Brightness;
|
||||
);
|
||||
|
||||
/// Sets the value of the specified position in the [BrightnessGrid].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `brightness_grid`: instance to write to
|
||||
/// - `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.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_set(
|
||||
brightness_grid: NonNull<BrightnessGrid>,
|
||||
x: usize,
|
||||
y: usize,
|
||||
value: Brightness,
|
||||
) {
|
||||
unsafe { (*brightness_grid.as_ptr()).set(x, y, value) };
|
||||
}
|
||||
wrap_method!(
|
||||
sp_brightness_grid :: BrightnessGrid;
|
||||
/// Sets the value of the specified position.
|
||||
///
|
||||
/// # 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.
|
||||
mut fn set(x: usize, y: usize, value: Brightness);
|
||||
);
|
||||
|
||||
/// Sets the value of all cells in the [BrightnessGrid].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `brightness_grid`: instance to write to
|
||||
/// - `value`: the value to set all cells to
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_fill(
|
||||
brightness_grid: NonNull<BrightnessGrid>,
|
||||
value: Brightness,
|
||||
) {
|
||||
unsafe { (*brightness_grid.as_ptr()).fill(value) };
|
||||
}
|
||||
wrap_method!(
|
||||
sp_brightness_grid :: BrightnessGrid;
|
||||
/// Sets the value of all cells.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `value`: the value to set all cells to
|
||||
mut fn fill(value: Brightness);
|
||||
);
|
||||
|
||||
/// Gets the width of the [BrightnessGrid] instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `brightness_grid`: instance to read from
|
||||
///
|
||||
/// returns: width
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_width(
|
||||
brightness_grid: NonNull<BrightnessGrid>,
|
||||
) -> usize {
|
||||
unsafe { brightness_grid.as_ref().width() }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_brightness_grid :: BrightnessGrid;
|
||||
/// Gets the width of the grid.
|
||||
ref fn width() -> usize;
|
||||
);
|
||||
|
||||
/// Gets the height of the [BrightnessGrid] instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `brightness_grid`: instance to read from
|
||||
///
|
||||
/// returns: height
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_height(
|
||||
brightness_grid: NonNull<BrightnessGrid>,
|
||||
) -> usize {
|
||||
unsafe { brightness_grid.as_ref().height() }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_brightness_grid :: BrightnessGrid;
|
||||
/// Gets the height of the grid.
|
||||
ref fn height() -> usize;
|
||||
);
|
||||
|
||||
/// Gets an unsafe reference to the data of the [BrightnessGrid] instance.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the brightness grid.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `brightness_grid`: instance to read from
|
||||
///
|
||||
/// returns: slice of bytes underlying the `brightness_grid`.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_brightness_grid_unsafe_data_ref(
|
||||
brightness_grid: NonNull<BrightnessGrid>,
|
||||
) -> ByteSlice {
|
||||
//noinspection RsAssertEqual
|
||||
const _: () = assert!(size_of::<Brightness>() == 1);
|
||||
wrap_method!(
|
||||
sp_brightness_grid :: BrightnessGrid;
|
||||
/// Gets an unsafe reference to the data of the instance.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the grid.
|
||||
mut fn data_ref_mut() -> ByteSlice;
|
||||
|br_slice| unsafe {
|
||||
//noinspection RsAssertEqual
|
||||
const _: () = assert!(size_of::<Brightness>() == 1);
|
||||
|
||||
let data = unsafe { (*brightness_grid.as_ptr()).data_ref_mut() };
|
||||
unsafe {
|
||||
ByteSlice::from_slice(transmute::<&mut [Brightness], &mut [u8]>(data))
|
||||
}
|
||||
}
|
||||
ByteSlice::from_slice(transmute::<&mut [Brightness], &mut [u8]>(br_slice))
|
||||
};
|
||||
);
|
||||
|
||||
/// Creates a [BrightnessGridCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::ByteSlice,
|
||||
macros::{wrap_clone, wrap_free},
|
||||
macros::{wrap_clone, wrap_free, wrap_method},
|
||||
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
|
||||
};
|
||||
use servicepoint::{CharGrid, CharGridCommand, Grid, Origin, Packet};
|
||||
|
@ -42,85 +42,63 @@ pub unsafe extern "C" fn sp_char_grid_load(
|
|||
wrap_clone!(CharGrid, sp_char_grid);
|
||||
wrap_free!(CharGrid, sp_char_grid);
|
||||
|
||||
/// Returns the current value at the specified position.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `char_grid`: instance to read from
|
||||
/// - `x` and `y`: position of the cell to read
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when accessing `x` or `y` out of bounds
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_char_grid_get(
|
||||
char_grid: NonNull<CharGrid>,
|
||||
x: usize,
|
||||
y: usize,
|
||||
) -> u32 {
|
||||
unsafe { char_grid.as_ref().get(x, y) as u32 }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_char_grid :: 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
|
||||
ref fn get(x: usize, y: usize) -> u32;
|
||||
| char | char as u32
|
||||
);
|
||||
|
||||
/// Sets the value of the specified position in the [CharGrid].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `char_grid`: instance to write to
|
||||
/// - `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
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_char_grid_set(
|
||||
char_grid: NonNull<CharGrid>,
|
||||
x: usize,
|
||||
y: usize,
|
||||
value: u32,
|
||||
) {
|
||||
unsafe { (*char_grid.as_ptr()).set(x, y, char::from_u32(value).unwrap()) };
|
||||
}
|
||||
wrap_method!(
|
||||
sp_char_grid :: CharGrid;
|
||||
/// 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`.
|
||||
mut fn set(x: usize, y: usize, value: u32);
|
||||
let value = char::from_u32(value).unwrap();
|
||||
);
|
||||
|
||||
/// Sets the value of all cells in the [CharGrid].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `char_grid`: instance to write to
|
||||
/// - `value`: the value to set all cells to
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_char_grid_fill(
|
||||
char_grid: NonNull<CharGrid>,
|
||||
value: u32,
|
||||
) {
|
||||
unsafe { (*char_grid.as_ptr()).fill(char::from_u32(value).unwrap()) };
|
||||
}
|
||||
wrap_method!(
|
||||
sp_char_grid :: CharGrid;
|
||||
/// 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`.
|
||||
mut fn fill(value: u32);
|
||||
let value = char::from_u32(value).unwrap();
|
||||
);
|
||||
|
||||
/// Gets the width of the [CharGrid] instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `char_grid`: instance to read from
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_char_grid_width(
|
||||
char_grid: NonNull<CharGrid>,
|
||||
) -> usize {
|
||||
unsafe { char_grid.as_ref().width() }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_char_grid :: CharGrid;
|
||||
/// Gets the width of the grid.
|
||||
ref fn width() -> usize;
|
||||
);
|
||||
|
||||
/// Gets the height of the [CharGrid] instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `char_grid`: instance to read from
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_char_grid_height(
|
||||
char_grid: NonNull<CharGrid>,
|
||||
) -> usize {
|
||||
unsafe { char_grid.as_ref().height() }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_char_grid :: CharGrid;
|
||||
/// Gets the height of the grid.
|
||||
ref fn height() -> usize;
|
||||
);
|
||||
|
||||
/// Creates a [CharGridCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
containers::ByteSlice,
|
||||
macros::{wrap_clone, wrap_free},
|
||||
macros::{wrap_clone, wrap_free, wrap_method},
|
||||
mem::{heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove},
|
||||
};
|
||||
use servicepoint::{
|
||||
|
@ -33,95 +33,68 @@ pub unsafe extern "C" fn sp_cp437_grid_load(
|
|||
wrap_clone!(Cp437Grid, sp_cp437_grid);
|
||||
wrap_free!(Cp437Grid, sp_cp437_grid);
|
||||
|
||||
/// Gets the current value at the specified position.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `cp437_grid`: instance to read from
|
||||
/// - `x` and `y`: position of the cell to read
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - when accessing `x` or `y` out of bounds
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_get(
|
||||
cp437_grid: NonNull<Cp437Grid>,
|
||||
x: usize,
|
||||
y: usize,
|
||||
) -> u8 {
|
||||
unsafe { cp437_grid.as_ref().get(x, y) }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_cp437 :: Cp437Grid;
|
||||
/// Gets 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
|
||||
ref fn get(x: usize, y: usize) -> u8;
|
||||
);
|
||||
|
||||
/// Sets the value of the specified position in the [Cp437Grid].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `cp437_grid`: instance to write to
|
||||
/// - `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
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_set(
|
||||
cp437_grid: NonNull<Cp437Grid>,
|
||||
x: usize,
|
||||
y: usize,
|
||||
value: u8,
|
||||
) {
|
||||
unsafe { (*cp437_grid.as_ptr()).set(x, y, value) };
|
||||
}
|
||||
wrap_method!(
|
||||
sp_cp437 :: Cp437Grid;
|
||||
/// Sets the value at the specified position.
|
||||
///
|
||||
/// # 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
|
||||
mut fn set(x: usize, y: usize, value: u8);
|
||||
);
|
||||
|
||||
/// Sets the value of all cells in the [Cp437Grid].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `cp437_grid`: instance to write to
|
||||
/// - `value`: the value to set all cells to
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_fill(
|
||||
cp437_grid: NonNull<Cp437Grid>,
|
||||
value: u8,
|
||||
) {
|
||||
unsafe { (*cp437_grid.as_ptr()).fill(value) };
|
||||
}
|
||||
wrap_method!(
|
||||
sp_cp437 :: Cp437Grid;
|
||||
/// Sets the value of all cells in the grid.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `cp437_grid`: instance to write to
|
||||
/// - `value`: the value to set all cells to
|
||||
mut fn fill(value: u8);
|
||||
);
|
||||
|
||||
/// Gets the width of the [Cp437Grid] instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `cp437_grid`: instance to read from
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_width(
|
||||
cp437_grid: NonNull<Cp437Grid>,
|
||||
) -> usize {
|
||||
unsafe { cp437_grid.as_ref().width() }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_cp437 :: Cp437Grid;
|
||||
/// Gets the width of the grid.
|
||||
ref fn width() -> usize;
|
||||
);
|
||||
|
||||
/// Gets the height of the [Cp437Grid] instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `cp437_grid`: instance to read from
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_height(
|
||||
cp437_grid: NonNull<Cp437Grid>,
|
||||
) -> usize {
|
||||
unsafe { cp437_grid.as_ref().height() }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_cp437 :: Cp437Grid;
|
||||
/// Gets the height of the grid.
|
||||
ref fn height() -> usize;
|
||||
);
|
||||
|
||||
/// Gets an unsafe reference to the data of the [Cp437Grid] instance.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the grid.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cp437_grid_unsafe_data_ref(
|
||||
cp437_grid: NonNull<Cp437Grid>,
|
||||
) -> ByteSlice {
|
||||
unsafe { ByteSlice::from_slice((*cp437_grid.as_ptr()).data_ref_mut()) }
|
||||
}
|
||||
wrap_method!(
|
||||
sp_cp437 :: Cp437Grid;
|
||||
/// Gets an unsafe reference to the data of the grid.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the instance.
|
||||
mut fn data_ref_mut() -> ByteSlice;
|
||||
| slice | unsafe { ByteSlice::from_slice(slice) };
|
||||
);
|
||||
|
||||
/// Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue