Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleGuest committed May 10, 2024
1 parent 391d96f commit f4608d1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cube/src/buzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<'d> Buzzer<'d> {
return;
}

// unimplemented!()
unimplemented!()
// let mut channel0 = self.ledc.get_channel(
// channel::Number::Channel0,
// io.pins.gpio8.into_push_pull_output(),
Expand Down
19 changes: 7 additions & 12 deletions cube/src/cube_man.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ impl CubeManGame {
{
self.floors.pop_front();

let span = unsafe {
CubeRng(RNG.assume_init_mut().random() as u64).random_range(2..=3) as usize
};
let span =
unsafe { CubeRng(RNG.assume_init_mut().random() as u64).random_range(2..=3) };

let mut floor = self.floor_gen.floor(self.depth);
if let Some(ref mut floor) = floor {
Expand Down Expand Up @@ -101,8 +100,7 @@ impl CubeManGame {
&self
.floors
.iter()
.filter(|f| f.is_some())
.map(|f| f.clone().unwrap())
.filter_map(|f| f.clone())
.collect::<Vec<_>>(),
&np,
) {
Expand Down Expand Up @@ -275,7 +273,7 @@ impl Floor {
fn new(ft: FloorType, data: &[Position]) -> Self {
Self {
r#type: ft,
data: data.into_iter().map(|p| p.into()).collect::<Vec<_>>(),
data: data.iter().map(|p| p.into()).collect::<Vec<_>>(),
}
}
}
Expand Down Expand Up @@ -303,15 +301,13 @@ impl FloorGen {
/// 随机生成地板
fn random(level: usize) -> Option<Floor> {
// 概率生成地板
let per =
unsafe { CubeRng(RNG.assume_init_mut().random() as u64).random_range(1..=10) as usize };
let per = unsafe { CubeRng(RNG.assume_init_mut().random() as u64).random_range(1..=10) };
if per < 7 {
return None;
}

// 地板长度
let len =
unsafe { CubeRng(RNG.assume_init_mut().random() as u64).random_range(3..=5) as usize };
let len = unsafe { CubeRng(RNG.assume_init_mut().random() as u64).random_range(3..=5) };
let mut data = Vec::<Position>::with_capacity(len);
for i in 0..len {
data.push((i, 0).into());
Expand Down Expand Up @@ -348,8 +344,7 @@ impl FloorGen {
}
floors.push_back(floor);

let span =
unsafe { CubeRng(RNG.assume_init_mut().random() as u64).random_range(2..=6) as usize };
let span = unsafe { CubeRng(RNG.assume_init_mut().random() as u64).random_range(2..=6) };
for _ in 0..span {
floors.push_back(None);
}
Expand Down
7 changes: 2 additions & 5 deletions cube/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,11 @@ impl Timer {

/// 在某一列找
fn last(&self, rx: i32) -> Option<usize> {
let Some(last) = self
let last = self
.pixels
.iter()
.filter(|p| p.pixel.0.x == rx)
.max_by_key(|p| p.pixel.0.y)
else {
return None;
};
.max_by_key(|p| p.pixel.0.y)?;
self.pixels.iter().position(|p| p == last)
}

Expand Down
4 changes: 2 additions & 2 deletions cube_rand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ impl CubeRng {
};

let low = match range.start_bound() {
Bound::Unbounded => core::u32::MIN,
Bound::Unbounded => u32::MIN,
Bound::Included(&x) => x as u32,
Bound::Excluded(&x) => (x as u32).checked_add(1).unwrap_or_else(panic_empty_range),
};

let high = match range.end_bound() {
Bound::Unbounded => core::u32::MAX,
Bound::Unbounded => u32::MAX,
Bound::Included(&x) => x as u32,
Bound::Excluded(&x) => (x as u32).checked_sub(1).unwrap_or_else(panic_empty_range),
};
Expand Down

0 comments on commit f4608d1

Please # to comment.