tweak dsl
This commit is contained in:
parent
b92dcc565a
commit
a06c3a83aa
|
@ -125,8 +125,10 @@ wrap_methods!(
|
|||
/// 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) };
|
||||
mut fn data_ref_mut() -> ByteSlice {
|
||||
|
||||
return(slice) { unsafe { ByteSlice::from_slice(slice) } };
|
||||
};
|
||||
);
|
||||
|
||||
/// Consumes the Bitmap and returns the contained BitVec.
|
||||
|
|
|
@ -53,8 +53,10 @@ wrap_methods!(
|
|||
/// # Panics
|
||||
///
|
||||
/// - when accessing `index` out of bounds
|
||||
ref fn get(index: usize) -> bool;
|
||||
|result| result.map(|x| *x).unwrap_or(false);
|
||||
ref fn get(index: usize) -> bool {
|
||||
return(result) { result.map(|x| *x).unwrap_or(false) };
|
||||
};
|
||||
|
||||
|
||||
/// Sets the value of a bit.
|
||||
///
|
||||
|
@ -84,8 +86,9 @@ wrap_methods!(
|
|||
/// 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) };
|
||||
mut fn as_raw_mut_slice() -> ByteSlice {
|
||||
return(slice) { unsafe { ByteSlice::from_slice(slice) } };
|
||||
};
|
||||
);
|
||||
|
||||
/// Creates a [BitVecCommand] and immediately turns that into a [Packet].
|
||||
|
|
|
@ -100,12 +100,13 @@ wrap_methods!(
|
|||
/// 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);
|
||||
mut fn data_ref_mut() -> ByteSlice {
|
||||
return(br_slice) { unsafe {
|
||||
//noinspection RsAssertEqual
|
||||
const _: () = assert!(size_of::<Brightness>() == 1);
|
||||
|
||||
ByteSlice::from_slice(transmute::<&mut [Brightness], &mut [u8]>(br_slice))
|
||||
ByteSlice::from_slice(transmute::<&mut [Brightness], &mut [u8]>(br_slice))
|
||||
}};
|
||||
};
|
||||
);
|
||||
|
||||
|
|
|
@ -54,8 +54,9 @@ wrap_methods!(
|
|||
/// # Panics
|
||||
///
|
||||
/// - when accessing `x` or `y` out of bounds
|
||||
ref fn get(x: usize, y: usize) -> u32;
|
||||
| char | char as u32;
|
||||
ref fn get(x: usize, y: usize) -> u32 {
|
||||
return(char) { char as u32 };
|
||||
};
|
||||
|
||||
/// Sets the value of the specified position in the grid.
|
||||
///
|
||||
|
@ -70,8 +71,9 @@ wrap_methods!(
|
|||
///
|
||||
/// - 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();
|
||||
mut fn set(x: usize, y: usize, value: u32) {
|
||||
prepare(value) { char::from_u32(value).unwrap() };
|
||||
};
|
||||
|
||||
/// Sets the value of all cells in the grid.
|
||||
///
|
||||
|
@ -79,8 +81,9 @@ wrap_methods!(
|
|||
///
|
||||
/// - `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();
|
||||
mut fn fill(value: u32) {
|
||||
prepare(value) { char::from_u32(value).unwrap() };
|
||||
};
|
||||
|
||||
/// Gets the width of the grid.
|
||||
ref fn width() -> usize;
|
||||
|
|
|
@ -77,8 +77,9 @@ wrap_methods!(
|
|||
/// 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) };
|
||||
mut fn data_ref_mut() -> ByteSlice {
|
||||
return(slice) { unsafe { ByteSlice::from_slice(slice) } };
|
||||
};
|
||||
);
|
||||
|
||||
/// Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
|
||||
|
|
|
@ -41,8 +41,12 @@ macro_rules! wrap_methods {
|
|||
$(
|
||||
$(#[$meta:meta])+
|
||||
$ref_or_mut:ident fn $function:ident($($param_name:ident: $param_type:ty),*)
|
||||
$(-> $return_type:ty$(; |$it:ident | $return_expr:expr)?)?;
|
||||
$($(let $param_let_name:ident = $param_let_expr:expr);+;)?
|
||||
$(-> $return_type:ty)?
|
||||
$({
|
||||
$($(prepare($param_let_name:ident) $param_let_expr:block);+;)?
|
||||
$(return($it:ident) $return_expr:block;)?
|
||||
})?
|
||||
;
|
||||
)*
|
||||
) => {
|
||||
paste::paste! {
|
||||
|
@ -57,9 +61,9 @@ macro_rules! wrap_methods {
|
|||
$($param_name: $param_type),*
|
||||
) $(-> $return_type)? {
|
||||
let instance = unsafe { $crate::macros:: [< nonnull_as_ $ref_or_mut >] !(instance) };
|
||||
$(
|
||||
$($(
|
||||
$(let $param_let_name = $param_let_expr;)*
|
||||
)?
|
||||
)?)?
|
||||
#[allow(
|
||||
unused_variables,
|
||||
reason = "This variable may not be used depending on macro variables" )]
|
||||
|
@ -69,8 +73,8 @@ macro_rules! wrap_methods {
|
|||
let $it = result;
|
||||
let result = $return_expr;
|
||||
)?
|
||||
return result;
|
||||
)?
|
||||
return result;
|
||||
}
|
||||
)*
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue