Skip to content

Commit 2997bee

Browse files
committed
Fix cargo clippy warnings
1 parent 00f6c64 commit 2997bee

9 files changed

Lines changed: 55 additions & 50 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
target/
2-
notes.yml
2+
*.yml

src/arguments.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ impl Options {
1919
pub fn read() -> Options {
2020
let arguments = Self::get_arguments();
2121
let receiver_address = value_t!(arguments.value_of("receiver_address"), SocketAddr)
22-
.unwrap_or("0.0.0.0:9999".parse().unwrap());
23-
let default_host_address = receiver_address.clone();
22+
.unwrap_or_else(|_| "0.0.0.0:9999".parse().unwrap());
2423

2524
let parsed_arguments = Options {
2625
host_address : value_t!(arguments.value_of("host_address"), SocketAddr)
27-
.unwrap_or(default_host_address),
26+
.unwrap_or(receiver_address),
2827
volume : value_t!(arguments.value_of("volume"), f32)
2928
.unwrap_or(1.0),
3029
record_file : value_t!(arguments.value_of("record_file"), String)
@@ -39,9 +38,9 @@ impl Options {
3938
.unwrap_or(0),
4039
mark_duration : value_t!(arguments.value_of("mark_duration"), u64)
4140
.unwrap_or(500),
42-
receiver_address : receiver_address,
41+
receiver_address,
4342
sender_address : value_t!(arguments.value_of("sender_address"), SocketAddr)
44-
.unwrap_or("0.0.0.0:0".parse().unwrap()),
43+
.unwrap_or_else(|_| "0.0.0.0:0".parse().unwrap()),
4544
};
4645

4746
parsed_arguments

src/game.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ impl PianoKeyboard {
3333
let player = Player::new();
3434

3535
PianoKeyboard {
36-
sequence: sequence,
37-
volume: volume,
38-
sound_duration: sound_duration,
39-
mark_duration: mark_duration,
40-
color: color,
41-
player: player,
36+
sequence,
37+
volume,
38+
sound_duration,
39+
mark_duration,
40+
color,
41+
player,
4242
recorder: NoteRecorder::new(),
4343
}
4444
}
@@ -62,7 +62,7 @@ impl PianoKeyboard {
6262
self.mark_duration,
6363
);
6464

65-
if let Some(_) = &self.recorder.record_file {
65+
if self.recorder.record_file.is_some(){
6666
self.recorder.write_note(note);
6767
}
6868
}
@@ -72,7 +72,7 @@ impl PianoKeyboard {
7272
}
7373

7474
pub fn process_key(&mut self, key: KeyEvent) -> Option<GameEvent> {
75-
let note = match key {
75+
match key {
7676
KeyEvent::Right => {
7777
if self.sequence < 6 {
7878
self.sequence += 1;
@@ -112,10 +112,8 @@ impl PianoKeyboard {
112112
_ => notes::key_to_base_note(key, self.sequence)
113113
.and_then(|note| Note::from(&note, self.color, self.sound_duration))
114114
.map(GameEvent::Note),
115-
};
116-
note
115+
}
117116
}
118-
119117
}
120118

121119
#[cfg(test)]

src/game/notes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Note {
4141
for start_index in 1..note.len() {
4242
frequency = note[start_index..].parse();
4343
base_sound = note[..start_index].parse();
44-
if let Ok(_) = frequency {
44+
if frequency.is_ok() {
4545
break;
4646
}
4747
}
@@ -76,11 +76,11 @@ impl Note {
7676
Some(v) => Ok(Note {
7777
sound: format!("{}{}", base_sound, frequency),
7878
base: base_sounds[v].to_string(),
79-
frequency: frequency,
79+
frequency,
8080
position: init_poses[v] + 21 * ((frequency - factors[v]) as i16),
8181
white: whites[v],
82-
color: color,
83-
duration: duration,
82+
color,
83+
duration,
8484
}),
8585
None => Err(String::from("We're Fucked.")),
8686
}

src/game/notes/play.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Player {
1616
for base in &["a", "as", "b", "c", "cs", "d", "ds", "e", "f", "fs", "g", "gs"] {
1717
for frequency in -1..8_i8 {
1818
Self::read_note(*base, frequency)
19-
.and_then(|sample| {
19+
.map(|sample| {
2020
samples.insert(format!("{}{}", base, frequency), sample);
2121
Some(())
2222
});
@@ -63,6 +63,13 @@ impl Player {
6363
}
6464
}
6565

66+
impl Default for Player {
67+
fn default() -> Self {
68+
Self::new()
69+
}
70+
}
71+
72+
6673
#[cfg(test)]
6774
mod test {
6875
use super::Player;

src/game/notes_file.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ impl NoteReader {
3535
pub fn parse_notes(&self) -> Vec<FileNote> {
3636
let mut counter = 1;
3737
let mut file_base_notes: Vec<FileNote> = Vec::new();
38-
loop {
39-
match self.parse_yaml_entry(counter) {
40-
Ok(v) => file_base_notes.push(v),
41-
Err(_) => break,
42-
}
38+
while let Ok(v) = self.parse_yaml_entry(counter) {
39+
file_base_notes.push(v);
4340
counter += 1;
4441
}
4542
file_base_notes
@@ -54,9 +51,9 @@ impl NoteReader {
5451
let base_note = x[1].as_str().unwrap();
5552
let duration = Duration::from_millis(x[2].as_i64().unwrap() as u64);
5653
Ok(FileNote {
57-
delay: delay,
54+
delay,
5855
base_note: base_note.to_string(),
59-
duration: duration,
56+
duration,
6057
})
6158
},
6259
_ => Err(String::from("Could not parse note")),
@@ -128,3 +125,10 @@ impl NoteRecorder {
128125
self.previous_note_time = time;
129126
}
130127
}
128+
129+
impl Default for NoteRecorder {
130+
fn default() -> Self {
131+
Self::new()
132+
}
133+
}
134+

src/main.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,14 @@ fn game_loop(stdin: &mut SyncReader, keyboard: &Arc<Mutex<PianoKeyboard>>, event
7474

7575
loop {
7676
if let Some(event) = stdin.next() {
77-
match event {
78-
InputEvent::Keyboard(key) => {
79-
match keyboard.lock().unwrap().process_key(key) {
80-
Some(GameEvent::Note(note)) => {
81-
event_sender.lock().unwrap().tick(note).unwrap();
82-
}
83-
Some(GameEvent::Quit) => break,
84-
None => { },
85-
};
86-
},
87-
_ => { },
77+
if let InputEvent::Keyboard(key) = event {
78+
match keyboard.lock().unwrap().process_key(key) {
79+
Some(GameEvent::Note(note)) => {
80+
event_sender.lock().unwrap().tick(note).unwrap();
81+
}
82+
Some(GameEvent::Quit) => break,
83+
None => { },
84+
}
8885
}
8986
}
9087
}
@@ -163,7 +160,7 @@ fn main() -> Result<()> {
163160
let mut sync_stdin = input.read_sync();
164161

165162
let cursor = cursor();
166-
cursor.hide();
163+
cursor.hide().unwrap_or_default();
167164

168165
game_loop(&mut sync_stdin, &keyboard, &event_sender);
169166

src/network/receiver.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl Receiver {
1212
pub fn new(addr: SocketAddr) -> Result<Receiver> {
1313
let socket = UdpSocket::bind(&addr)?;
1414
Ok(Receiver {
15-
socket: socket,
15+
socket,
1616
})
1717
}
1818

@@ -24,9 +24,9 @@ impl Receiver {
2424

2525
let event: types::NetworkEvent = bincode::deserialize(&buf).unwrap();
2626
Ok(types::NetworkData {
27-
amt: amt,
28-
src: src,
29-
event: event,
27+
amt,
28+
src,
29+
event,
3030
})
3131
}
3232

@@ -38,9 +38,9 @@ impl Receiver {
3838

3939
let event: types::NetworkEvent = bincode::deserialize(&buf).unwrap();
4040
Ok(types::NetworkData {
41-
amt: amt,
42-
src: src,
43-
event: event,
41+
amt,
42+
src,
43+
event,
4444
})
4545
}
4646
}

src/network/sender.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ impl Sender {
1313
pub fn new(addr: SocketAddr, host_addr: SocketAddr) -> Result<Sender> {
1414
let socket = UdpSocket::bind(&addr)?;
1515
Ok(Sender {
16-
socket: socket,
17-
host_addr: host_addr,
16+
socket,
17+
host_addr,
1818
peer_addrs: Vec::new(),
1919
})
2020
}

0 commit comments

Comments
 (0)