unifiy special handling of params and return
This commit is contained in:
		
							parent
							
								
									92ce27af68
								
							
						
					
					
						commit
						e434130784
					
				
					 8 changed files with 82 additions and 66 deletions
				
			
		| 
						 | 
				
			
			@ -109,7 +109,7 @@ 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.
 | 
			
		||||
    mut fn data_ref_mut() -> ByteSlice {
 | 
			
		||||
        return(slice) { unsafe { ByteSlice::from_slice(slice) } };
 | 
			
		||||
    mut fn data_ref_mut(instance) -> ByteSlice {
 | 
			
		||||
        unsafe { ByteSlice::from_slice(instance.data_ref_mut()) }
 | 
			
		||||
    };
 | 
			
		||||
);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -71,8 +71,8 @@ wrap_methods!(DisplayBitVec;
 | 
			
		|||
    /// # Panics
 | 
			
		||||
    ///
 | 
			
		||||
    /// - when accessing `index` out of bounds
 | 
			
		||||
    ref fn get(index: usize) -> bool {
 | 
			
		||||
        return(result) { result.map(|x| *x).unwrap_or(false) };
 | 
			
		||||
    ref fn get(instance, index: usize) -> bool {
 | 
			
		||||
         instance.get(index).map(|x| *x).unwrap_or(false)
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    /// Sets the value of a bit.
 | 
			
		||||
| 
						 | 
				
			
			@ -85,25 +85,25 @@ wrap_methods!(DisplayBitVec;
 | 
			
		|||
    /// # Panics
 | 
			
		||||
    ///
 | 
			
		||||
    /// - when accessing `index` out of bounds
 | 
			
		||||
    mut fn set(index: usize, value: bool);
 | 
			
		||||
    mut fn set(instance, index: usize, value: bool);
 | 
			
		||||
 | 
			
		||||
    /// Sets the value of all bits.
 | 
			
		||||
    ///
 | 
			
		||||
    /// # Arguments
 | 
			
		||||
    ///
 | 
			
		||||
    /// - `value`: the value to set all bits to
 | 
			
		||||
    mut fn fill(value: bool);
 | 
			
		||||
    mut fn fill(instance, value: bool);
 | 
			
		||||
 | 
			
		||||
    /// Gets the length in bits.
 | 
			
		||||
    ref fn len() -> usize;
 | 
			
		||||
    ref fn len(instance) -> usize;
 | 
			
		||||
 | 
			
		||||
    /// Returns true if length is 0.
 | 
			
		||||
    ref fn is_empty() -> bool;
 | 
			
		||||
    ref fn is_empty(instance) -> bool;
 | 
			
		||||
 | 
			
		||||
    /// 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 {
 | 
			
		||||
        return(slice) { unsafe { ByteSlice::from_slice(slice) } };
 | 
			
		||||
    mut fn as_raw_mut_slice(instance) -> ByteSlice {
 | 
			
		||||
        unsafe { ByteSlice::from_slice(instance.as_raw_mut_slice()) }
 | 
			
		||||
    };
 | 
			
		||||
);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -77,14 +77,13 @@ wrap_methods!(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 {
 | 
			
		||||
        return(br_slice) {
 | 
			
		||||
            //noinspection RsAssertEqual
 | 
			
		||||
            const _: () = assert!(size_of::<Brightness>() == 1);
 | 
			
		||||
    mut fn data_ref_mut(instance) -> ByteSlice {
 | 
			
		||||
        //noinspection RsAssertEqual
 | 
			
		||||
        const _: () = assert!(size_of::<Brightness>() == 1);
 | 
			
		||||
 | 
			
		||||
            unsafe {
 | 
			
		||||
                ByteSlice::from_slice(transmute::<&mut [Brightness], &mut [u8]>(br_slice))
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
        let br_slice = instance.data_ref_mut();
 | 
			
		||||
        unsafe {
 | 
			
		||||
            ByteSlice::from_slice(transmute::<&mut [Brightness], &mut [u8]>(br_slice))
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -72,8 +72,8 @@ wrap_methods!(CharGrid;
 | 
			
		|||
    /// # Panics
 | 
			
		||||
    ///
 | 
			
		||||
    /// - when accessing `x` or `y` out of bounds
 | 
			
		||||
    ref fn get(x: usize, y: usize) -> u32 {
 | 
			
		||||
        return(char) { char as u32 };
 | 
			
		||||
    ref fn get(instance, x: usize, y: usize) -> u32 {
 | 
			
		||||
        instance.get(x, y) as u32
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    /// Sets the value of the specified position in the grid.
 | 
			
		||||
| 
						 | 
				
			
			@ -89,8 +89,8 @@ wrap_methods!(CharGrid;
 | 
			
		|||
    ///
 | 
			
		||||
    /// - 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) {
 | 
			
		||||
        prepare(value) { char::from_u32(value).unwrap() };
 | 
			
		||||
    mut fn set(instance, x: usize, y: usize, value: u32) {
 | 
			
		||||
        instance.set(x, y, char::from_u32(value).unwrap())
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    /// Sets the value of all cells in the grid.
 | 
			
		||||
| 
						 | 
				
			
			@ -99,7 +99,7 @@ wrap_methods!(CharGrid;
 | 
			
		|||
    ///
 | 
			
		||||
    /// - `value`: the value to set all cells to
 | 
			
		||||
    /// - when providing values that cannot be converted to Rust's `char`.
 | 
			
		||||
    mut fn fill(value: u32) {
 | 
			
		||||
        prepare(value) { char::from_u32(value).unwrap() };
 | 
			
		||||
    mut fn fill(instance, value: u32) {
 | 
			
		||||
        instance.fill(char::from_u32(value).unwrap())
 | 
			
		||||
    };
 | 
			
		||||
);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -55,7 +55,7 @@ wrap_methods!(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 {
 | 
			
		||||
        return(slice) { unsafe { ByteSlice::from_slice(slice) } };
 | 
			
		||||
    mut fn data_ref_mut(instance) -> ByteSlice {
 | 
			
		||||
        unsafe { ByteSlice::from_slice(instance.data_ref_mut()) }
 | 
			
		||||
    };
 | 
			
		||||
);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,10 +23,10 @@ macro_rules! derive_get_width_height {
 | 
			
		|||
    ($object_type:ident) => {
 | 
			
		||||
        $crate::macros::wrap_methods! {$object_type;
 | 
			
		||||
            /// Gets the width.
 | 
			
		||||
            ref fn width() -> usize;
 | 
			
		||||
            ref fn width(instance) -> usize;
 | 
			
		||||
 | 
			
		||||
            /// Gets the height.
 | 
			
		||||
            ref fn height() -> usize;
 | 
			
		||||
            ref fn height(instance) -> usize;
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -45,7 +45,7 @@ macro_rules! wrap_grid {
 | 
			
		|||
            /// # Panics
 | 
			
		||||
            ///
 | 
			
		||||
            /// - when accessing `x` or `y` out of bounds
 | 
			
		||||
            ref fn get(x: usize, y: usize) -> $value_type;
 | 
			
		||||
            ref fn get(instance, x: usize, y: usize) -> $value_type;
 | 
			
		||||
 | 
			
		||||
            /// Sets the value of the specified position.
 | 
			
		||||
            ///
 | 
			
		||||
| 
						 | 
				
			
			@ -57,14 +57,14 @@ macro_rules! wrap_grid {
 | 
			
		|||
            /// # Panics
 | 
			
		||||
            ///
 | 
			
		||||
            /// - when accessing `x` or `y` out of bounds
 | 
			
		||||
            mut fn set(x: usize, y: usize, value: $value_type);
 | 
			
		||||
            mut fn set(instance, x: usize, y: usize, value: $value_type);
 | 
			
		||||
 | 
			
		||||
            /// Sets the state of all cells in the grid.
 | 
			
		||||
            ///
 | 
			
		||||
            /// # Arguments
 | 
			
		||||
            ///
 | 
			
		||||
            /// - `value`: the value to set all cells to
 | 
			
		||||
            mut fn fill(value: $value_type);
 | 
			
		||||
            mut fn fill(instance, value: $value_type);
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue