Skip to content

Commit

Permalink
Run clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed Jul 2, 2023
1 parent edb691a commit 134f0b2
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 58 deletions.
12 changes: 4 additions & 8 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,9 @@ impl fmt::Display for Command {
Self::Noop => write!(f, "No-op"),
Self::PaletteAdd(c) => write!(f, "Add {color} to palette", color = c),
Self::PaletteClear => write!(f, "Clear palette"),
Self::PaletteGradient(cs, ce, n) => write!(
f,
"Create {} colors gradient from {} to {}",
number = n,
colorstart = cs,
colorend = ce
),
Self::PaletteGradient(cs, ce, n) => {
write!(f, "Create {n} colors gradient from {cs} to {ce}")
}
Self::PaletteSample => write!(f, "Sample palette from view"),
Self::PaletteSort => write!(f, "Sort palette colors"),
Self::Pan(x, 0) if *x > 0 => write!(f, "Pan workspace right"),
Expand Down Expand Up @@ -435,7 +431,7 @@ impl From<Value> for f32 {
impl From<Value> for f64 {
fn from(other: Value) -> f64 {
if let Value::F64(x) = other {
return x as f64;
return x;
}
panic!("expected {:?} to be a `f64`", other);
}
Expand Down
8 changes: 4 additions & 4 deletions src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,14 +749,14 @@ pub fn draw_view_composites<R>(session: &Session, v: &View<R>) -> sprite2d::Batc

pub fn draw_help(session: &Session, text: &mut TextBatch, shape: &mut shape2d::Batch) {
shape.add(Shape::Rectangle(
Rect::origin(session.width as f32, session.height as f32),
Rect::origin(session.width, session.height),
ZDepth(0.0),
Rotation::ZERO,
Stroke::new(1., color::RED.into()),
Fill::Empty,
));
shape.add(Shape::Rectangle(
Rect::origin(session.width as f32, session.height as f32),
Rect::origin(session.width, session.height),
self::HELP_LAYER,
Rotation::ZERO,
Stroke::NONE,
Expand All @@ -773,7 +773,7 @@ pub fn draw_help(session: &Session, text: &mut TextBatch, shape: &mut shape2d::B
platform::Key::Escape,
),
left_margin,
session.height as f32 - self::MARGIN - self::LINE_HEIGHT,
session.height - self::MARGIN - self::LINE_HEIGHT,
self::HELP_LAYER,
color::LIGHT_GREY,
TextAlign::Left,
Expand Down Expand Up @@ -859,7 +859,7 @@ pub fn draw_help(session: &Session, text: &mut TextBatch, shape: &mut shape2d::B
}

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

text.add(
l,
Expand Down
5 changes: 1 addition & 4 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ impl FromStr for Event {
.followed_by(end())
.parse(p)
.map_err(|(e, _)| e)?;
Ok((
Event::CursorMoved(platform::LogicalPosition::new(x as f64, y as f64)),
p,
))
Ok((Event::CursorMoved(platform::LogicalPosition::new(x, y)), p))
}
"keyboard/input" => {
let ((k, s), p) = parser::param::<platform::Key>()
Expand Down
12 changes: 4 additions & 8 deletions src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl DigestState {
let mut frames = Vec::new();
let path = path.as_ref();

match File::open(&path) {
match File::open(path) {
Ok(f) => {
let r = io::BufReader::new(f);
for line in r.lines() {
Expand Down Expand Up @@ -97,8 +97,10 @@ pub enum ExecutionMode {
/// Execution mode. Controls whether the session is playing or recording
/// commands.
// TODO: Make this a `struct` and have `ExecutionMode`.
#[derive(Default)]
pub enum Execution {
/// Normal execution. User inputs are processed normally.
#[default]
Normal,
/// Recording user inputs to log.
Recording {
Expand Down Expand Up @@ -198,7 +200,7 @@ impl Execution {
} => {
let mut frames = Vec::new();

match File::open(&path) {
match File::open(path) {
Ok(f) => {
let r = io::BufReader::new(f);
for line in r.lines() {
Expand Down Expand Up @@ -372,12 +374,6 @@ impl Execution {
}
}

impl Default for Execution {
fn default() -> Self {
Execution::Normal
}
}

pub struct GifRecorder {
width: u16,
height: u16,
Expand Down
15 changes: 6 additions & 9 deletions src/gl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,14 +1015,13 @@ impl Renderer {
.map_err(Error::Texture)?;
}
ViewOp::Yank(src) => {
let (_, pixels) = v.layer.get_snapshot_rect(&src.map(|n| n as i32)).unwrap();
let (_, pixels) = v.layer.get_snapshot_rect(&src.map(|n| n)).unwrap();
let (w, h) = (src.width() as u32, src.height() as u32);
let [paste_w, paste_h] = self.paste.size();

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

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

if paste_w != w || paste_h != h {
self.paste =
Texture::new(&mut self.ctx, [w as u32, h as u32], 0, self::SAMPLER)
.map_err(Error::Texture)?;
self.paste = Texture::new(&mut self.ctx, [w, h], 0, self::SAMPLER)
.map_err(Error::Texture)?;
}

match dir {
Expand Down
2 changes: 1 addition & 1 deletion src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn read<R: io::Read>(reader: R) -> io::Result<(Vec<u8>, u32, u32)> {
));
}

let (width, height) = (info.width as u32, info.height as u32);
let (width, height) = (info.width, info.height);

let mut buffer: Vec<u8> = vec![0; info.buffer_size()];
reader
Expand Down
29 changes: 9 additions & 20 deletions src/session.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(clippy::needless_collect)]
///! Session
//! Session
use crate::autocomplete::FileCompleter;
use crate::brush::*;
use crate::cmd::{self, Command, CommandLine, KeyMapping, Op, Value};
Expand Down Expand Up @@ -68,9 +68,10 @@ pub type SessionCoords = Point<Session, f32>;

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

impl Default for Mode {
fn default() -> Self {
Mode::Normal
}
}

impl fmt::Display for Mode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down Expand Up @@ -227,9 +222,10 @@ pub enum State {
}

/// An editing tool.
#[derive(PartialEq, Eq, Debug, Clone)]
#[derive(PartialEq, Eq, Debug, Clone, Default)]
pub enum Tool {
/// The standard drawing tool.
#[default]
Brush,
/// Used for filling enclosed regions with color.
FloodFill,
Expand All @@ -239,12 +235,6 @@ pub enum Tool {
Pan(PanState),
}

impl Default for Tool {
fn default() -> Self {
Tool::Brush
}
}

#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum PanState {
Panning,
Expand Down Expand Up @@ -1545,10 +1535,10 @@ impl Session {
let view = self.view(id);
let delay = time::Duration::from_millis(self.settings["animation/delay"].to_u64());

view.save_gif(&path, delay, &palette, scale)?
view.save_gif(path, delay, &palette, scale)?
}
"svg" => self.view(id).save_svg(&path, scale)?,
"png" => self.view(id).save_png(&path, scale)?,
"svg" => self.view(id).save_svg(path, scale)?,
"png" => self.view(id).save_png(path, scale)?,
_ => {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
Expand Down Expand Up @@ -2190,7 +2180,7 @@ impl Session {
let path = path.as_ref();
debug!("source: {}", path.display());

File::open(&path)
File::open(path)
.or_else(|_| File::open(self.proj_dirs.config_dir().join(path)))
.and_then(|f| self.source_reader(io::BufReader::new(f), path))
.map_err(|e| {
Expand Down Expand Up @@ -2678,7 +2668,6 @@ impl Session {
}
}
}
#[allow(mutable_borrow_reservation_conflict)]
Command::Toggle(ref k) => match self.settings.get(k) {
Some(Value::Bool(b)) => self.command(Command::Set(k.clone(), Value::Bool(!b))),
Some(_) => {
Expand Down
4 changes: 2 additions & 2 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl ViewExtent {
/// Compute the frame index, given a point.
/// Warning: can underflow.
pub fn to_frame(self, p: ViewCoords<u32>) -> usize {
(p.x / (self.fw as u32)) as usize
(p.x / self.fw) as usize
}
}

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

Ok(e_id)
}
Expand Down
4 changes: 2 additions & 2 deletions src/view/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ impl ViewResource {

{
// Convert animation strip into discrete frames for gif encoder.
let nrows = fh as usize * nframes;
let row_nbytes = fw as usize;
let nrows = fh * nframes;
let row_nbytes = fw;

for i in 0..nrows {
let offset = i * row_nbytes;
Expand Down

0 comments on commit 134f0b2

Please sign in to comment.