Skip to content

Commit 28aad69

Browse files
committed
Fix clippy lints
1 parent 02fca81 commit 28aad69

15 files changed

Lines changed: 55 additions & 91 deletions

File tree

ink/src/lib.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,14 @@
1919
use scof::{Cursor, Fraction, Marking, Note, Pitch, Scof};
2020

2121
/// This is the entire program context.
22+
#[derive(Default)]
2223
pub struct Program {
2324
/// The save file.
2425
pub scof: Scof,
2526
/// Current cursor
2627
pub cursor: Cursor,
2728
}
2829

29-
impl Default for Program {
30-
fn default() -> Self {
31-
Self {
32-
scof: Scof::default(),
33-
cursor: Cursor::default(),
34-
}
35-
}
36-
}
37-
3830
impl Program {
3931
/// Create a new program.
4032
pub fn new() -> Self {

scof/src/fraction.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use std::{
66
cmp::Ordering,
7-
convert::TryInto,
87
fmt,
98
ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign},
109
str::FromStr,
@@ -90,9 +89,9 @@ impl Add for Fraction {
9089
return other;
9190
}
9291

93-
let (self_mul, other_mul, den) = if self.den % other.den == 0 {
92+
let (self_mul, other_mul, den) = if self.den.is_multiple_of(other.den) {
9493
(1, self.den / other.den, self.den)
95-
} else if other.den % self.den == 0 {
94+
} else if other.den.is_multiple_of(self.den) {
9695
(other.den / self.den, 1, other.den)
9796
} else {
9897
(other.den, self.den, self.den * other.den)
@@ -117,9 +116,9 @@ impl Sub for Fraction {
117116
type Output = Fraction;
118117

119118
fn sub(self, other: Fraction) -> Self::Output {
120-
let (self_mul, other_mul, den) = if self.den % other.den == 0 {
119+
let (self_mul, other_mul, den) = if self.den.is_multiple_of(other.den) {
121120
(1, self.den / other.den, self.den)
122-
} else if other.den % self.den == 0 {
121+
} else if other.den.is_multiple_of(self.den) {
123122
(other.den / self.den, 1, other.den)
124123
} else {
125124
(other.den, self.den, self.den * other.den)
@@ -200,41 +199,41 @@ impl fmt::Display for Fraction {
200199
}
201200

202201
pub trait IsZero {
203-
fn is_zero(self) -> bool;
202+
fn is_zero(&self) -> bool;
204203
}
205204

206205
impl IsZero for u8 {
207-
fn is_zero(self) -> bool {
208-
self == 0
206+
fn is_zero(&self) -> bool {
207+
*self == 0
209208
}
210209
}
211210

212211
impl IsZero for u16 {
213-
fn is_zero(self) -> bool {
214-
self == 0
212+
fn is_zero(&self) -> bool {
213+
*self == 0
215214
}
216215
}
217216

218217
impl IsZero for u32 {
219-
fn is_zero(self) -> bool {
220-
self == 0
218+
fn is_zero(&self) -> bool {
219+
*self == 0
221220
}
222221
}
223222

224223
impl IsZero for u64 {
225-
fn is_zero(self) -> bool {
226-
self == 0
224+
fn is_zero(&self) -> bool {
225+
*self == 0
227226
}
228227
}
229228

230229
impl IsZero for u128 {
231-
fn is_zero(self) -> bool {
232-
self == 0
230+
fn is_zero(&self) -> bool {
231+
*self == 0
233232
}
234233
}
235234

236235
impl IsZero for Fraction {
237-
fn is_zero(self) -> bool {
236+
fn is_zero(&self) -> bool {
238237
self.num == 0 && self.den != 0
239238
}
240239
}
@@ -353,6 +352,6 @@ mod tests {
353352
assert!(Fraction::new(50, 25) > Fraction::new(99, 50));
354353
assert!(Fraction::new(3, 4) > Fraction::new(1, 2));
355354
assert!(Fraction::new(1, 3) > Fraction::new(1, 4));
356-
assert_eq!(false, Fraction::new(0, 3) > Fraction::new(0, 4));
355+
assert!(Fraction::new(0, 3) <= Fraction::new(0, 4));
357356
}
358357
}

scof/src/lib.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
// You should have received a copy of the GNU General Public License
1717
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1818

19-
#![allow(clippy::blacklisted_name)] // bar is a useful musical term
20-
21-
use std::{convert::TryInto, str::FromStr};
19+
use std::str::FromStr;
2220

2321
use devout::{Tag, log};
2422
use muon_rs as muon;
@@ -172,7 +170,7 @@ impl FromStr for Marking {
172170
type Err = ();
173171

174172
fn from_str(s: &str) -> Result<Self, Self::Err> {
175-
Ok(Marking::Note(s.parse::<Note>().and_then(Ok)?))
173+
Ok(Marking::Note(s.parse::<Note>()?))
176174
}
177175
}
178176

@@ -198,8 +196,6 @@ pub enum Repeat {
198196
Ending(u8),
199197
}
200198

201-
/////////////////////
202-
//// ////
203199
/////////////////////
204200

205201
/// A waveform.
@@ -691,7 +687,7 @@ impl Scof {
691687

692688
let b = cursor.marking;
693689

694-
new_notes.extend(notes.drain(0..b.try_into().unwrap()));
690+
new_notes.extend(notes.drain(0..usize::from(b)));
695691

696692
let mut i = 0;
697693
i = loop {
@@ -790,7 +786,7 @@ impl Scof {
790786
/// Insert a note after the cursor.
791787
fn insert_after(&mut self, cursor: Cursor, marking: Marking) -> Option<()> {
792788
self.chan_notes_mut(cursor.right_unchecked())?
793-
.insert((cursor.marking + 1).try_into().unwrap(), marking);
789+
.insert(usize::from(cursor.marking + 1), marking);
794790
Some(())
795791
}
796792
}

scof/src/note/articulation.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//!
2-
31
use std::{fmt, str::FromStr};
42

53
/// An articulation (affects how the note is played).

scof/src/note/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
//! - `@`: harmonic (smaller o)
6262
//! - `|`: pedal
6363
64-
use std::{convert::TryInto, fmt, str::FromStr};
64+
use std::{fmt, str::FromStr};
6565

6666
use crate::Fraction;
6767

@@ -146,11 +146,7 @@ impl fmt::Display for Note {
146146
impl Note {
147147
/// Get the note's visual distance above middle C (C4).
148148
pub fn visual_distance(&self, i: usize) -> Option<Steps> {
149-
if let Some(pitch) = self.pitch.get(i) {
150-
Some(pitch.visual_distance())
151-
} else {
152-
None
153-
}
149+
self.pitch.get(i).map(|pitch| pitch.visual_distance())
154150
}
155151

156152
/// Set pitch class and octave.

scof/src/note/pitch.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,14 @@ impl FromStr for PitchName {
5050
/// A Pitch Accidental.
5151
#[derive(Copy, Clone, Debug, PartialEq)]
5252
pub enum PitchAccidental {
53-
///
5453
DoubleFlat,
55-
///
5654
FlatQuarterFlat,
57-
///
5855
Flat,
59-
///
6056
QuarterFlat,
61-
///
6257
Natural,
63-
///
6458
QuarterSharp,
65-
///
6659
Sharp,
67-
///
6860
SharpQuarterSharp,
69-
///
7061
DoubleSharp,
7162
}
7263

@@ -265,9 +256,7 @@ impl Pitch {
265256
let steps = self.0.name as i32;
266257

267258
// Calculate total number of steps from middle C.
268-
Steps {
269-
0: steps + octaves * 7,
270-
}
259+
Steps(steps + octaves * 7)
271260
}
272261
}
273262

sfff/src/font.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use std::{
2-
convert::TryInto,
3-
io::{Read, Write},
4-
};
1+
use std::io::{Read, Write};
52

63
use crate::glyph::Glyph;
74

@@ -38,21 +35,15 @@ pub struct SfFontMetadata {
3835
pub font_name: String,
3936

4037
// Non-glyph components (in thousandths of stave space)
41-
///
4238
pub stave_line_thickness: i32,
43-
///
4439
pub stem_thickness: i32,
45-
///
4640
pub ledger_line_thickness: i32,
47-
///
4841
pub ledger_line_extension: i32,
4942
/// Also used for ties
5043
pub slur_endpoint_thickness: i32,
5144
/// Also used for ties
5245
pub slur_midpoint_thickness: i32,
53-
///
5446
pub barline_thickness: i32,
55-
///
5647
pub thick_barline_thickness: i32,
5748
/// Space between two barlines
5849
pub barlines_space: i32,
@@ -65,7 +56,6 @@ pub struct SfFontMetadata {
6556
/// Cresc., Dim., hairpin thickness (pedal, octave, ending, lyric melisma,
6657
/// tuple brackets)
6758
pub hairpin_thickness: i32,
68-
///
6959
pub rehearsal_box_thickness: i32,
7060

7161
// Glyph metadata (Notehead & Stem Positions)
@@ -164,7 +154,7 @@ fn read_short_str<T: Read>(reader: &mut T) -> Result<String, ReadError> {
164154
reader
165155
.read_exact(&mut buf)
166156
.map_err(|_| ReadError::UnexpectedEOF)?;
167-
Ok(String::from_utf8(buf).map_err(|_| ReadError::InvalidText)?)
157+
String::from_utf8(buf).map_err(|_| ReadError::InvalidText)
168158
}
169159

170160
/// Write a short string (0-255 bytes)

staverator/src/bar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ impl BarElem {
105105
measure, 0, /* i chan */
106106
0, /* marking */
107107
);
108-
let reset_cursor = curs.clone();
108+
let reset_cursor = curs;
109109

110110
// Make voicings for each stave.
111111
let mut stave_voicing = vec![];
112112
let mut stave_cursor = vec![];
113113
for chan in 0..scof.movement[0].bar[0].chan.len() as u16 {
114114
curs = reset_cursor.chan(chan);
115-
let notes = notator::notate(scof, cursor.clone(), curs.clone());
115+
let notes = notator::notate(scof, *cursor, curs);
116116
stave_voicing.push(notes);
117117
stave_cursor.push(*cursor == curs);
118118
}

staverator/src/beaming.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,24 @@ pub enum BeamProp {
5454
Flag,
5555
}
5656

57+
/// A voicing that may be beamed or flagged
58+
type BeamedOrFlaggedVoicing = (BeamProp, u16, f32, (Vec<Pitch>, Steps));
59+
60+
/// A voicing that is part of a beamed group
61+
type BeamedVoicings = (u16, f32, (Vec<Pitch>, Steps), bool);
62+
5763
/// All of the beams in a measure.
5864
pub(crate) struct Beams {
5965
// Duration not notated yet in the measure.
6066
dur: u16,
6167
// Notes that may be flagged or beamed.
62-
short: VecDeque<(BeamProp, u16, f32, (Vec<Pitch>, Steps))>,
68+
short: VecDeque<BeamedOrFlaggedVoicing>,
6369
// Last was short?
6470
last_short: bool,
6571
// Minimum duration within current beam.
6672
min_dur: u16,
6773
// Notes in the beamed group.
68-
notes: Vec<(u16, f32, (Vec<Pitch>, Steps), bool)>,
74+
notes: Vec<BeamedVoicings>,
6975
// For iterator.
7076
queued: Option<Short>,
7177
}

staverator/src/notator.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// You should have received a copy of the GNU General Public License
1717
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1818

19-
use std::convert::TryInto;
20-
2119
use scof::{Cursor, Marking, Pitch, Scof};
2220

2321
/// A voicing is the set of notes at one position in a piece
@@ -118,5 +116,5 @@ impl<'a> Iterator for Notator<'a> {
118116

119117
/// Notate one measure
120118
pub fn notate(scof: &Scof, cursor: Cursor, curs: Cursor) -> Vec<Voicing> {
121-
Notator::new(scof, cursor.clone(), curs.clone()).collect()
119+
Notator::new(scof, cursor, curs).collect()
122120
}

0 commit comments

Comments
 (0)