Skip to content

Commit b26c5ba

Browse files
committed
Run clippy
1 parent 18625a6 commit b26c5ba

File tree

9 files changed

+33
-58
lines changed

9 files changed

+33
-58
lines changed

src/cmd.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,9 @@ impl fmt::Display for Command {
175175
Self::Noop => write!(f, "No-op"),
176176
Self::PaletteAdd(c) => write!(f, "Add {color} to palette", color = c),
177177
Self::PaletteClear => write!(f, "Clear palette"),
178-
Self::PaletteGradient(cs, ce, n) => write!(
179-
f,
180-
"Create {} colors gradient from {} to {}",
181-
number = n,
182-
colorstart = cs,
183-
colorend = ce
184-
),
178+
Self::PaletteGradient(cs, ce, n) => {
179+
write!(f, "Create {n} colors gradient from {cs} to {ce}")
180+
}
185181
Self::PaletteSample => write!(f, "Sample palette from view"),
186182
Self::PaletteSort => write!(f, "Sort palette colors"),
187183
Self::Pan(x, 0) if *x > 0 => write!(f, "Pan workspace right"),
@@ -435,7 +431,7 @@ impl From<Value> for f32 {
435431
impl From<Value> for f64 {
436432
fn from(other: Value) -> f64 {
437433
if let Value::F64(x) = other {
438-
return x as f64;
434+
return x;
439435
}
440436
panic!("expected {:?} to be a `f64`", other);
441437
}

src/draw.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,14 +749,14 @@ pub fn draw_view_composites<R>(session: &Session, v: &View<R>) -> sprite2d::Batc
749749

750750
pub fn draw_help(session: &Session, text: &mut TextBatch, shape: &mut shape2d::Batch) {
751751
shape.add(Shape::Rectangle(
752-
Rect::origin(session.width as f32, session.height as f32),
752+
Rect::origin(session.width, session.height),
753753
ZDepth(0.0),
754754
Rotation::ZERO,
755755
Stroke::new(1., color::RED.into()),
756756
Fill::Empty,
757757
));
758758
shape.add(Shape::Rectangle(
759-
Rect::origin(session.width as f32, session.height as f32),
759+
Rect::origin(session.width, session.height),
760760
self::HELP_LAYER,
761761
Rotation::ZERO,
762762
Stroke::NONE,
@@ -773,7 +773,7 @@ pub fn draw_help(session: &Session, text: &mut TextBatch, shape: &mut shape2d::B
773773
platform::Key::Escape,
774774
),
775775
left_margin,
776-
session.height as f32 - self::MARGIN - self::LINE_HEIGHT,
776+
session.height - self::MARGIN - self::LINE_HEIGHT,
777777
self::HELP_LAYER,
778778
color::LIGHT_GREY,
779779
TextAlign::Left,
@@ -859,7 +859,7 @@ pub fn draw_help(session: &Session, text: &mut TextBatch, shape: &mut shape2d::B
859859
}
860860

861861
for (i, l) in session.help().iter().enumerate() {
862-
let y = session.height as f32 - (i + 4) as f32 * self::LINE_HEIGHT;
862+
let y = session.height - (i + 4) as f32 * self::LINE_HEIGHT;
863863

864864
text.add(
865865
l,

src/event.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ impl FromStr for Event {
125125
.followed_by(end())
126126
.parse(p)
127127
.map_err(|(e, _)| e)?;
128-
Ok((
129-
Event::CursorMoved(platform::LogicalPosition::new(x as f64, y as f64)),
130-
p,
131-
))
128+
Ok((Event::CursorMoved(platform::LogicalPosition::new(x, y)), p))
132129
}
133130
"keyboard/input" => {
134131
let ((k, s), p) = parser::param::<platform::Key>()

src/execution.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl DigestState {
4848
let mut frames = Vec::new();
4949
let path = path.as_ref();
5050

51-
match File::open(&path) {
51+
match File::open(path) {
5252
Ok(f) => {
5353
let r = io::BufReader::new(f);
5454
for line in r.lines() {
@@ -97,8 +97,10 @@ pub enum ExecutionMode {
9797
/// Execution mode. Controls whether the session is playing or recording
9898
/// commands.
9999
// TODO: Make this a `struct` and have `ExecutionMode`.
100+
#[derive(Default)]
100101
pub enum Execution {
101102
/// Normal execution. User inputs are processed normally.
103+
#[default]
102104
Normal,
103105
/// Recording user inputs to log.
104106
Recording {
@@ -198,7 +200,7 @@ impl Execution {
198200
} => {
199201
let mut frames = Vec::new();
200202

201-
match File::open(&path) {
203+
match File::open(path) {
202204
Ok(f) => {
203205
let r = io::BufReader::new(f);
204206
for line in r.lines() {
@@ -372,12 +374,6 @@ impl Execution {
372374
}
373375
}
374376

375-
impl Default for Execution {
376-
fn default() -> Self {
377-
Execution::Normal
378-
}
379-
}
380-
381377
pub struct GifRecorder {
382378
width: u16,
383379
height: u16,

src/gl/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,14 +1015,13 @@ impl Renderer {
10151015
.map_err(Error::Texture)?;
10161016
}
10171017
ViewOp::Yank(src) => {
1018-
let (_, pixels) = v.layer.get_snapshot_rect(&src.map(|n| n as i32)).unwrap();
1018+
let (_, pixels) = v.layer.get_snapshot_rect(&src.map(|n| n)).unwrap();
10191019
let (w, h) = (src.width() as u32, src.height() as u32);
10201020
let [paste_w, paste_h] = self.paste.size();
10211021

10221022
if paste_w != w || paste_h != h {
1023-
self.paste =
1024-
Texture::new(&mut self.ctx, [w as u32, h as u32], 0, self::SAMPLER)
1025-
.map_err(Error::Texture)?;
1023+
self.paste = Texture::new(&mut self.ctx, [w, h], 0, self::SAMPLER)
1024+
.map_err(Error::Texture)?;
10261025
}
10271026
let body = util::align_u8(&pixels);
10281027

@@ -1031,15 +1030,13 @@ impl Renderer {
10311030
.map_err(Error::Texture)?;
10321031
}
10331032
ViewOp::Flip(src, dir) => {
1034-
let (_, mut pixels) =
1035-
v.layer.get_snapshot_rect(&src.map(|n| n as i32)).unwrap();
1033+
let (_, mut pixels) = v.layer.get_snapshot_rect(&src.map(|n| n)).unwrap();
10361034
let (w, h) = (src.width() as u32, src.height() as u32);
10371035
let [paste_w, paste_h] = self.paste.size();
10381036

10391037
if paste_w != w || paste_h != h {
1040-
self.paste =
1041-
Texture::new(&mut self.ctx, [w as u32, h as u32], 0, self::SAMPLER)
1042-
.map_err(Error::Texture)?;
1038+
self.paste = Texture::new(&mut self.ctx, [w, h], 0, self::SAMPLER)
1039+
.map_err(Error::Texture)?;
10431040
}
10441041

10451042
match dir {

src/image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn read<R: io::Read>(reader: R) -> io::Result<(Vec<u8>, u32, u32)> {
112112
));
113113
}
114114

115-
let (width, height) = (info.width as u32, info.height as u32);
115+
let (width, height) = (info.width, info.height);
116116

117117
let mut buffer: Vec<u8> = vec![0; info.buffer_size()];
118118
reader

src/session.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(clippy::needless_collect)]
2-
///! Session
2+
//! Session
33
use crate::autocomplete::FileCompleter;
44
use crate::brush::*;
55
use crate::cmd::{self, Command, CommandLine, KeyMapping, Op, Value};
@@ -68,9 +68,10 @@ pub type SessionCoords = Point<Session, f32>;
6868

6969
/// An editing mode the `Session` can be in.
7070
/// Some of these modes are inspired by vi.
71-
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
71+
#[derive(Eq, PartialEq, Copy, Clone, Debug, Default)]
7272
pub enum Mode {
7373
/// Allows the user to paint pixels.
74+
#[default]
7475
Normal,
7576
/// Allows pixels to be selected, copied and manipulated visually.
7677
Visual(VisualState),
@@ -83,12 +84,6 @@ pub enum Mode {
8384
Help,
8485
}
8586

86-
impl Default for Mode {
87-
fn default() -> Self {
88-
Mode::Normal
89-
}
90-
}
91-
9287
impl fmt::Display for Mode {
9388
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9489
match self {
@@ -227,9 +222,10 @@ pub enum State {
227222
}
228223

229224
/// An editing tool.
230-
#[derive(PartialEq, Eq, Debug, Clone)]
225+
#[derive(PartialEq, Eq, Debug, Clone, Default)]
231226
pub enum Tool {
232227
/// The standard drawing tool.
228+
#[default]
233229
Brush,
234230
/// Used for filling enclosed regions with color.
235231
FloodFill,
@@ -239,12 +235,6 @@ pub enum Tool {
239235
Pan(PanState),
240236
}
241237

242-
impl Default for Tool {
243-
fn default() -> Self {
244-
Tool::Brush
245-
}
246-
}
247-
248238
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
249239
pub enum PanState {
250240
Panning,
@@ -1545,10 +1535,10 @@ impl Session {
15451535
let view = self.view(id);
15461536
let delay = time::Duration::from_millis(self.settings["animation/delay"].to_u64());
15471537

1548-
view.save_gif(&path, delay, &palette, scale)?
1538+
view.save_gif(path, delay, &palette, scale)?
15491539
}
1550-
"svg" => self.view(id).save_svg(&path, scale)?,
1551-
"png" => self.view(id).save_png(&path, scale)?,
1540+
"svg" => self.view(id).save_svg(path, scale)?,
1541+
"png" => self.view(id).save_png(path, scale)?,
15521542
_ => {
15531543
return Err(io::Error::new(
15541544
io::ErrorKind::InvalidInput,
@@ -2190,7 +2180,7 @@ impl Session {
21902180
let path = path.as_ref();
21912181
debug!("source: {}", path.display());
21922182

2193-
File::open(&path)
2183+
File::open(path)
21942184
.or_else(|_| File::open(self.proj_dirs.config_dir().join(path)))
21952185
.and_then(|f| self.source_reader(io::BufReader::new(f), path))
21962186
.map_err(|e| {
@@ -2678,7 +2668,6 @@ impl Session {
26782668
}
26792669
}
26802670
}
2681-
#[allow(mutable_borrow_reservation_conflict)]
26822671
Command::Toggle(ref k) => match self.settings.get(k) {
26832672
Some(Value::Bool(b)) => self.command(Command::Set(k.clone(), Value::Bool(!b))),
26842673
Some(_) => {

src/view.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl ViewExtent {
7373
/// Compute the frame index, given a point.
7474
/// Warning: can underflow.
7575
pub fn to_frame(self, p: ViewCoords<u32>) -> usize {
76-
(p.x / (self.fw as u32)) as usize
76+
(p.x / self.fw) as usize
7777
}
7878
}
7979

@@ -550,7 +550,7 @@ impl View<ViewResource> {
550550
format!("\"{}\" already exists", path.display()),
551551
));
552552
}
553-
let (e_id, _) = self.save(rect, &path)?;
553+
let (e_id, _) = self.save(rect, path)?;
554554

555555
Ok(e_id)
556556
}

src/view/resource.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ impl ViewResource {
216216

217217
{
218218
// Convert animation strip into discrete frames for gif encoder.
219-
let nrows = fh as usize * nframes;
220-
let row_nbytes = fw as usize;
219+
let nrows = fh * nframes;
220+
let row_nbytes = fw;
221221

222222
for i in 0..nrows {
223223
let offset = i * row_nbytes;

0 commit comments

Comments
 (0)