File tree 2 files changed +12
-3
lines changed
2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -205,7 +205,8 @@ impl Buttons {
205
205
/// Get the current touch pad state.
206
206
#[ must_use]
207
207
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) } ;
209
210
if raw == 0xffff {
210
211
None
211
212
} else {
@@ -219,7 +220,8 @@ pub fn read_pad(p: Peer) -> Option<Pad> {
219
220
/// Get the currently pressed buttons.
220
221
#[ must_use]
221
222
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) } ;
223
225
Buttons {
224
226
a : has_bit_set ( raw, 0 ) ,
225
227
b : has_bit_set ( raw, 1 ) ,
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ pub struct Peers(pub(crate) u32);
16
16
17
17
impl Peers {
18
18
/// Iterate over peers.
19
+ #[ must_use]
19
20
pub fn iter ( & self ) -> PeersIter {
20
21
PeersIter {
21
22
peer : 0 ,
@@ -24,21 +25,25 @@ impl Peers {
24
25
}
25
26
26
27
/// Check if the given peer is online.
28
+ #[ must_use]
27
29
pub fn contains ( & self , p : & Peer ) -> bool {
28
30
self . 0 >> p. 0 & 1 != 0
29
31
}
30
32
31
33
/// Get the number of peers online.
32
34
///
33
35
/// 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
34
38
pub fn len ( & self ) -> usize {
35
39
self . 0 . count_ones ( ) as usize
36
40
}
37
41
38
42
/// Convert the list of peers into a vector.
39
43
#[ cfg( feature = "alloc" ) ]
44
+ #[ must_use]
40
45
pub fn as_vec ( & self ) -> alloc:: vec:: Vec < Peer > {
41
- alloc :: vec :: Vec :: from_iter ( self . iter ( ) )
46
+ self . iter ( ) . collect ( )
42
47
}
43
48
}
44
49
@@ -86,12 +91,14 @@ impl Iterator for PeersIter {
86
91
}
87
92
88
93
/// Get the peer cirresponding to the local device.
94
+ #[ must_use]
89
95
pub fn get_me ( ) -> Peer {
90
96
let me = unsafe { bindings:: get_me ( ) } ;
91
97
Peer ( me as u8 )
92
98
}
93
99
94
100
/// Get the list of peers online.
101
+ #[ must_use]
95
102
pub fn get_peers ( ) -> Peers {
96
103
let peers = unsafe { bindings:: get_peers ( ) } ;
97
104
Peers ( peers)
You can’t perform that action at this time.
0 commit comments