Skip to content

Commit 8944861

Browse files
committed
apply strict clippy suggestions
1 parent 4850d96 commit 8944861

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/input.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ impl Buttons {
205205
/// Get the current touch pad state.
206206
#[must_use]
207207
pub fn read_pad(p: Peer) -> Option<Pad> {
208-
let raw = unsafe { bindings::read_pad(p.0 as u32) };
208+
let p = u32::from(p.0);
209+
let raw = unsafe { bindings::read_pad(p) };
209210
if raw == 0xffff {
210211
None
211212
} else {
@@ -219,7 +220,8 @@ pub fn read_pad(p: Peer) -> Option<Pad> {
219220
/// Get the currently pressed buttons.
220221
#[must_use]
221222
pub fn read_buttons(p: Peer) -> Buttons {
222-
let raw = unsafe { bindings::read_buttons(p.0 as u32) };
223+
let p = u32::from(p.0);
224+
let raw = unsafe { bindings::read_buttons(p) };
223225
Buttons {
224226
a: has_bit_set(raw, 0),
225227
b: has_bit_set(raw, 1),

src/net.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub struct Peers(pub(crate) u32);
1616

1717
impl Peers {
1818
/// Iterate over peers.
19+
#[must_use]
1920
pub fn iter(&self) -> PeersIter {
2021
PeersIter {
2122
peer: 0,
@@ -24,21 +25,25 @@ impl Peers {
2425
}
2526

2627
/// Check if the given peer is online.
28+
#[must_use]
2729
pub fn contains(&self, p: &Peer) -> bool {
2830
self.0 >> p.0 & 1 != 0
2931
}
3032

3133
/// Get the number of peers online.
3234
///
3335
/// Never zero. 1 for local single-player game. 2 or more for multiplayer.
36+
#[must_use]
37+
#[allow(clippy::len_without_is_empty)] // always non-empty
3438
pub fn len(&self) -> usize {
3539
self.0.count_ones() as usize
3640
}
3741

3842
/// Convert the list of peers into a vector.
3943
#[cfg(feature = "alloc")]
44+
#[must_use]
4045
pub fn as_vec(&self) -> alloc::vec::Vec<Peer> {
41-
alloc::vec::Vec::from_iter(self.iter())
46+
self.iter().collect()
4247
}
4348
}
4449

@@ -86,12 +91,14 @@ impl Iterator for PeersIter {
8691
}
8792

8893
/// Get the peer cirresponding to the local device.
94+
#[must_use]
8995
pub fn get_me() -> Peer {
9096
let me = unsafe { bindings::get_me() };
9197
Peer(me as u8)
9298
}
9399

94100
/// Get the list of peers online.
101+
#[must_use]
95102
pub fn get_peers() -> Peers {
96103
let peers = unsafe { bindings::get_peers() };
97104
Peers(peers)

0 commit comments

Comments
 (0)