mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 17:41:33 +11:00
Final clippy lint fixes
This commit is contained in:
parent
bf9f298972
commit
ba35b85c81
|
@ -17,10 +17,10 @@ impl<const N: usize> Bitarray<N> {
|
|||
}
|
||||
|
||||
pub fn set(&mut self, index: usize, value: bool) {
|
||||
let value = value as u32;
|
||||
let value = u32::from(value);
|
||||
let mask = 1 << (index % 32);
|
||||
let value_mask = value << (index % 32);
|
||||
self.a[index / 32] = self.a[index / 32] & !mask | value_mask
|
||||
self.a[index / 32] = self.a[index / 32] & !mask | value_mask;
|
||||
}
|
||||
|
||||
pub fn first_zero(&self) -> Option<usize> {
|
||||
|
|
|
@ -89,11 +89,13 @@ pub struct HashMap<K, V> {
|
|||
|
||||
impl<K, V> HashMap<K, V> {
|
||||
/// Creates a `HashMap`
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Self::with_size(16)
|
||||
}
|
||||
|
||||
/// Creates an empty `HashMap` with specified internal size. The size must be a power of 2
|
||||
#[must_use]
|
||||
pub fn with_size(size: usize) -> Self {
|
||||
Self {
|
||||
nodes: NodeStorage::with_size(size),
|
||||
|
@ -103,6 +105,7 @@ impl<K, V> HashMap<K, V> {
|
|||
|
||||
/// Creates an empty `HashMap` which can hold at least `capacity` elements before resizing. The actual
|
||||
/// internal size may be larger as it must be a power of 2
|
||||
#[must_use]
|
||||
pub fn with_capacity(capacity: usize) -> Self {
|
||||
for i in 0..32 {
|
||||
let attempted_size = 1usize << i;
|
||||
|
@ -118,11 +121,13 @@ impl<K, V> HashMap<K, V> {
|
|||
}
|
||||
|
||||
/// Returns the number of elements in the map
|
||||
#[must_use]
|
||||
pub fn len(&self) -> usize {
|
||||
self.nodes.len()
|
||||
}
|
||||
|
||||
/// Returns the number of elements the map can hold
|
||||
#[must_use]
|
||||
pub fn capacity(&self) -> usize {
|
||||
self.nodes.capacity()
|
||||
}
|
||||
|
@ -149,21 +154,16 @@ impl<K, V> HashMap<K, V> {
|
|||
|
||||
/// An iterator visiting all key-value pairs in an arbitrary order
|
||||
pub fn iter(&self) -> impl Iterator<Item = (&'_ K, &'_ V)> {
|
||||
self.nodes
|
||||
.nodes
|
||||
.iter()
|
||||
.filter_map(|node| node.key_value_ref())
|
||||
self.nodes.nodes.iter().filter_map(Node::key_value_ref)
|
||||
}
|
||||
|
||||
/// An iterator visiting all key-value pairs in an arbitrary order, with mutable references to the values
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&'_ K, &'_ mut V)> {
|
||||
self.nodes
|
||||
.nodes
|
||||
.iter_mut()
|
||||
.filter_map(|node| node.key_value_mut())
|
||||
self.nodes.nodes.iter_mut().filter_map(Node::key_value_mut)
|
||||
}
|
||||
|
||||
/// Returns `true` if the map contains no elements
|
||||
#[must_use]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
|
@ -1179,7 +1179,7 @@ mod test {
|
|||
fn test_entry(_gba: &mut Gba) {
|
||||
let xs = [(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)];
|
||||
|
||||
let mut map: HashMap<_, _> = xs.iter().cloned().collect();
|
||||
let mut map: HashMap<_, _> = xs.iter().copied().collect();
|
||||
|
||||
// Existing key (insert)
|
||||
match map.entry(1) {
|
||||
|
|
|
@ -10,8 +10,8 @@ pub enum Tri {
|
|||
|
||||
impl From<(bool, bool)> for Tri {
|
||||
fn from(a: (bool, bool)) -> Tri {
|
||||
let b1 = a.0 as i8;
|
||||
let b2 = a.1 as i8;
|
||||
let b1 = i8::from(a.0);
|
||||
let b2 = i8::from(a.1);
|
||||
unsafe { core::mem::transmute(b2 - b1) }
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ impl Default for ButtonController {
|
|||
}
|
||||
|
||||
impl ButtonController {
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
let pressed = !unsafe { BUTTON_INPUT.read_volatile() };
|
||||
ButtonController {
|
||||
|
@ -60,6 +61,7 @@ impl ButtonController {
|
|||
self.current = !unsafe { BUTTON_INPUT.read_volatile() };
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn x_tri(&self) -> Tri {
|
||||
let left = self.is_pressed(Button::LEFT);
|
||||
let right = self.is_pressed(Button::RIGHT);
|
||||
|
@ -67,6 +69,7 @@ impl ButtonController {
|
|||
(left, right).into()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn y_tri(&self) -> Tri {
|
||||
let up = self.is_pressed(Button::UP);
|
||||
let down = self.is_pressed(Button::DOWN);
|
||||
|
@ -74,25 +77,30 @@ impl ButtonController {
|
|||
(up, down).into()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_pressed(&self, keys: Button) -> bool {
|
||||
let currently_pressed = self.current as u32;
|
||||
let currently_pressed = u32::from(self.current);
|
||||
let keys = keys.bits();
|
||||
(currently_pressed & keys) != 0
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_released(&self, keys: Button) -> bool {
|
||||
!self.is_pressed(keys)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_just_pressed(&self, keys: Button) -> bool {
|
||||
let current = self.current as u32;
|
||||
let previous = self.previous as u32;
|
||||
let current = u32::from(self.current);
|
||||
let previous = u32::from(self.previous);
|
||||
let keys = keys.bits();
|
||||
((current & keys) != 0) && ((previous & keys) == 0)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_just_released(&self, keys: Button) -> bool {
|
||||
let current = self.current as u32;
|
||||
let previous = self.previous as u32;
|
||||
let current = u32::from(self.current);
|
||||
let previous = u32::from(self.previous);
|
||||
let keys = keys.bits();
|
||||
((current & keys) == 0) && ((previous & keys) != 0)
|
||||
}
|
||||
|
|
|
@ -179,6 +179,7 @@ unsafe fn create_interrupt_inner(
|
|||
impl Drop for InterruptInner {
|
||||
fn drop(&mut self) {
|
||||
inner_drop(unsafe { Pin::new_unchecked(self) });
|
||||
#[allow(clippy::needless_pass_by_value)] // needed for safety reasons
|
||||
fn inner_drop(this: Pin<&mut InterruptInner>) {
|
||||
// drop the closure allocation safely
|
||||
let _closure_box =
|
||||
|
@ -300,6 +301,7 @@ pub struct VBlank {}
|
|||
impl VBlank {
|
||||
/// Handles setting up everything reqired to be able to use the wait for
|
||||
/// interrupt syscall.
|
||||
#[must_use]
|
||||
pub fn get() -> Self {
|
||||
interrupt_to_root(Interrupt::VBlank).add();
|
||||
VBlank {}
|
||||
|
@ -329,10 +331,10 @@ mod tests {
|
|||
let counter = Mutex::new(RefCell::new(0));
|
||||
let counter_2 = Mutex::new(RefCell::new(0));
|
||||
let _a = add_interrupt_handler(Interrupt::VBlank, |key: CriticalSection| {
|
||||
*counter.borrow(key).borrow_mut() += 1
|
||||
*counter.borrow(key).borrow_mut() += 1;
|
||||
});
|
||||
let _b = add_interrupt_handler(Interrupt::VBlank, |key: CriticalSection| {
|
||||
*counter_2.borrow(key).borrow_mut() += 1
|
||||
*counter_2.borrow(key).borrow_mut() += 1;
|
||||
});
|
||||
|
||||
let vblank = VBlank::get();
|
||||
|
|
|
@ -234,6 +234,7 @@ pub struct Gba {
|
|||
|
||||
impl Gba {
|
||||
#[doc(hidden)]
|
||||
#[must_use]
|
||||
pub unsafe fn new_in_entry() -> Self {
|
||||
GBASINGLE.take()
|
||||
}
|
||||
|
@ -365,7 +366,7 @@ mod test {
|
|||
break;
|
||||
}
|
||||
vblank.wait_for_vblank();
|
||||
counter += 1
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ fn is_running_in_mgba() -> bool {
|
|||
const NUMBER_OF_CYCLES: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x04FF_F800) };
|
||||
|
||||
pub fn number_of_cycles_tagged(tag: u16) {
|
||||
NUMBER_OF_CYCLES.set(tag)
|
||||
NUMBER_OF_CYCLES.set(tag);
|
||||
}
|
||||
|
||||
pub struct Mgba {
|
||||
|
@ -37,6 +37,7 @@ pub struct Mgba {
|
|||
}
|
||||
|
||||
impl Mgba {
|
||||
#[must_use]
|
||||
pub fn new() -> Option<Self> {
|
||||
if is_running_in_mgba() {
|
||||
Some(Mgba { bytes_written: 0 })
|
||||
|
|
|
@ -15,12 +15,14 @@ impl RandomNumberGenerator {
|
|||
/// Create a new random number generator with a fixed seed
|
||||
///
|
||||
/// Note that this seed is guaranteed to be the same between minor releases.
|
||||
#[must_use]
|
||||
pub const fn new() -> Self {
|
||||
Self::new_with_seed([1014776995, 476057059, 3301633994, 706340607])
|
||||
}
|
||||
|
||||
/// Produces a random number generator with the given initial state / seed.
|
||||
/// None of the values can be 0.
|
||||
#[must_use]
|
||||
pub const fn new_with_seed(seed: [u32; 4]) -> Self {
|
||||
// this can't be in a loop because const
|
||||
assert!(seed[0] != 0, "seed must not be 0");
|
||||
|
@ -54,6 +56,7 @@ static GLOBAL_RNG: Mutex<RefCell<RandomNumberGenerator>> =
|
|||
Mutex::new(RefCell::new(RandomNumberGenerator::new()));
|
||||
|
||||
/// Using a global random number generator, provides the next random number
|
||||
#[must_use]
|
||||
pub fn gen() -> i32 {
|
||||
free(|cs| GLOBAL_RNG.borrow(cs).borrow_mut().gen())
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ pub fn wait_for_vblank() {
|
|||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn div(numerator: i32, denominator: i32) -> (i32, i32, i32) {
|
||||
let divide: i32;
|
||||
let modulo: i32;
|
||||
|
@ -71,6 +72,7 @@ pub fn div(numerator: i32, denominator: i32) -> (i32, i32, i32) {
|
|||
(divide, modulo, abs_divide)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn sqrt(n: i32) -> i32 {
|
||||
let result: i32;
|
||||
unsafe {
|
||||
|
@ -86,6 +88,7 @@ pub fn sqrt(n: i32) -> i32 {
|
|||
result
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn arc_tan(n: i16) -> i16 {
|
||||
let result: i16;
|
||||
unsafe {
|
||||
|
@ -101,6 +104,7 @@ pub fn arc_tan(n: i16) -> i16 {
|
|||
result
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn arc_tan2(x: i16, y: i32) -> i16 {
|
||||
let result: i16;
|
||||
unsafe {
|
||||
|
|
|
@ -21,7 +21,7 @@ pub enum Divider {
|
|||
}
|
||||
|
||||
impl Divider {
|
||||
fn as_bits(&self) -> u16 {
|
||||
fn as_bits(self) -> u16 {
|
||||
use Divider::*;
|
||||
|
||||
match self {
|
||||
|
@ -68,6 +68,7 @@ impl Timer {
|
|||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn value(&self) -> u16 {
|
||||
self.data_register().get()
|
||||
}
|
||||
|
@ -90,7 +91,7 @@ impl Timer {
|
|||
}
|
||||
|
||||
pub fn set_interrupt(&mut self, interrupt: bool) -> &mut Self {
|
||||
let bit = interrupt as u16;
|
||||
let bit = u16::from(interrupt);
|
||||
self.control_register().set_bits(bit, 1, 6);
|
||||
self
|
||||
}
|
||||
|
@ -107,6 +108,7 @@ impl Timer {
|
|||
self.timer_number as usize
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn interrupt(&self) -> crate::interrupt::Interrupt {
|
||||
use crate::interrupt::Interrupt;
|
||||
match self.timer_number {
|
||||
|
|
Loading…
Reference in a new issue