This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

🚨 Lint & format

+37 -47
+5 -8
src/canvas.rs
··· 1 1 use core::panic; 2 2 use rayon::prelude::*; 3 3 use resvg::usvg; 4 - use std::{collections::HashMap, fs::OpenOptions, io::Write, ops::Range, sync::Arc}; 4 + use std::{collections::HashMap, ops::Range, sync::Arc}; 5 5 6 6 use itertools::Itertools as _; 7 7 use measure_time::info_time; ··· 216 216 info_time!("load_fonts"); 217 217 let usvg = load_fonts(&self.font_options)?; 218 218 self.fontdb = Some(usvg.fontdb); 219 - return Ok(()); 219 + Ok(()) 220 220 } 221 221 222 222 pub fn random_layer(&self, name: &str) -> Layer { ··· 475 475 return Ok(()); 476 476 } 477 477 478 - Ok(self 479 - .render_to_pixmap_no_cache(width, height) 480 - .and_then(|pixmap| { 481 - pixmap_to_png_data(pixmap).and_then(|data| write_png_data(data, at)) 482 - })?) 478 + self.render_to_pixmap_no_cache(width, height) 479 + .and_then(|pixmap| pixmap_to_png_data(pixmap).and_then(|data| write_png_data(data, at))) 483 480 } 484 481 } 485 482 ··· 667 664 668 665 let pixel = pixmap 669 666 .pixel(x as u32, y as u32) 670 - .expect(&format!("No pixel found at x, y = {x}, {y}")); 667 + .unwrap_or_else(|| panic!("No pixel found at x, y = {x}, {y}")); 671 668 672 669 chunk[0] = pixel.red(); 673 670 chunk[1] = pixel.green();
+1 -1
src/cli.rs
··· 1 + use crate::{Canvas, ColorMapping}; 1 2 use docopt::Docopt; 2 3 use measure_time::info_time; 3 4 use serde::Deserialize; 4 - use crate::{Canvas, ColorMapping}; 5 5 6 6 const USAGE: &str = " 7 7 â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„â–„
+5 -4
src/color.rs
··· 141 141 142 142 #[wasm_bindgen] 143 143 impl ColorMapping { 144 + // wasm_bindegen is not supported on trait impls 145 + #[allow(clippy::should_implement_trait)] 144 146 pub fn default() -> Self { 145 147 ColorMapping { 146 148 black: "black".to_string(), ··· 263 265 let mut mapping = ColorMapping::default(); 264 266 let file = File::open(path).unwrap(); 265 267 let lines = std::io::BufReader::new(file).lines(); 266 - for line in lines { 267 - if let Ok(line) = line { 268 - mapping.from_css_line(&line); 269 - } 268 + for line in lines.map_while(Result::ok) { 269 + mapping.from_css_line(&line); 270 270 } 271 271 mapping 272 272 } 273 273 274 + #[allow(clippy::wrong_self_convention)] 274 275 fn from_css_line(&mut self, line: &str) { 275 276 if let Some((name, value)) = line.trim().split_once(':') { 276 277 let value = value.trim().trim_end_matches(';').to_owned();
+1 -1
src/examples.rs
··· 139 139 let character = title[i..i + 1].to_owned(); 140 140 141 141 text_layer.add_object( 142 - &i.to_string(), 142 + i.to_string(), 143 143 Object::CenteredText(point, character, 30.0).color(Fill::Solid(Color::White)), 144 144 ); 145 145 }
+4 -4
src/layer.rs
··· 66 66 } 67 67 68 68 pub fn paint_all_objects(&mut self, fill: Fill) { 69 - for (_id, obj) in &mut self.objects { 69 + for obj in self.objects.values_mut() { 70 70 obj.fill = Some(fill); 71 71 } 72 72 self.flush(); 73 73 } 74 74 75 75 pub fn filter_all_objects(&mut self, filter: Filter) { 76 - for (_id, obj) in &mut self.objects { 76 + for obj in self.objects.values_mut() { 77 77 obj.filters.push(filter) 78 78 } 79 79 self.flush(); ··· 86 86 self.flush(); 87 87 } 88 88 89 - pub fn add_object<'a, N: Display>(&mut self, name: N, object: ColoredObject) { 89 + pub fn add_object<N: Display>(&mut self, name: N, object: ColoredObject) { 90 90 let name_str = format!("{}", name); 91 91 92 92 if self.objects.contains_key(&name_str) { ··· 96 96 self.set_object(name_str, object); 97 97 } 98 98 99 - pub fn set_object<'a, N: Display>(&mut self, name: N, object: ColoredObject) { 99 + pub fn set_object<N: Display>(&mut self, name: N, object: ColoredObject) { 100 100 let name_str = format!("{}", name); 101 101 102 102 self.objects.insert(name_str, object);
+4 -4
src/lib.rs
··· 8 8 pub mod examples; 9 9 pub mod fill; 10 10 pub mod filter; 11 + pub mod fonts; 11 12 pub mod layer; 12 13 pub mod midi; 13 14 pub mod objects; ··· 17 18 pub mod transform; 18 19 pub mod ui; 19 20 pub mod video; 20 - pub mod web; 21 21 pub mod vst; 22 - pub mod fonts; 22 + pub mod web; 23 23 pub use animation::*; 24 24 use anyhow::Result; 25 25 pub use audio::*; ··· 36 36 pub use sync::Syncable; 37 37 pub use transform::*; 38 38 pub use video::*; 39 - pub use web::log; 40 39 pub use vst::*; 40 + pub use web::log; 41 41 42 42 use nanoid::nanoid; 43 43 use std::fs::{self}; ··· 58 58 pub duration_override: Option<usize>, 59 59 } 60 60 61 - impl<'a, C> Context<'a, C> { 61 + impl<C> Context<'_, C> { 62 62 pub fn stem(&self, name: &str) -> StemAtInstant { 63 63 let stems = &self.syncdata.stems; 64 64 if !stems.contains_key(name) {
-1
src/main.rs
··· 5 5 *, 6 6 }; 7 7 8 - #[macro_use] 9 8 extern crate log; 10 9 11 10 pub fn main() -> Result<()> {
+12 -15
src/midi.rs
··· 139 139 } 140 140 } 141 141 142 - fn load_notes<'a>( 142 + fn load_notes( 143 143 source: &PathBuf, 144 144 progressbar: Option<&ProgressBar>, 145 145 ) -> (Now, HashMap<String, Vec<Note>>) { ··· 152 152 } 153 153 154 154 let raw = std::fs::read(source) 155 - .expect(format!("Failed to read MIDI file {}", source.to_str().unwrap()).as_str()); 155 + .unwrap_or_else(|_| panic!("Failed to read MIDI file {}", source.to_str().unwrap())); 156 156 let midifile = midly::Smf::parse(&raw).unwrap(); 157 157 158 158 let mut timeline = Timeline::new(); ··· 224 224 let mut absolute_tick_to_ms = HashMap::<u32, usize>::new(); 225 225 let mut last_tick = 0; 226 226 for (tick, tracks) in timeline.iter().sorted_by_key(|(tick, _)| *tick) { 227 - for (_, event) in tracks { 228 - match event.kind { 229 - TrackEventKind::Meta(MetaMessage::Tempo(tempo)) => { 230 - now.tempo = tempo.as_int() as usize; 231 - } 232 - _ => {} 227 + for event in tracks.values() { 228 + if let TrackEventKind::Meta(MetaMessage::Tempo(tempo)) = event.kind { 229 + now.tempo = tempo.as_int() as usize; 233 230 } 234 231 } 235 232 let delta = tick - last_tick; ··· 249 246 let mut stem_notes = StemNotes::new(); 250 247 for (tick, tracks) in timeline.iter().sorted_by_key(|(tick, _)| *tick) { 251 248 for (track_name, event) in tracks { 252 - match event.kind { 253 - TrackEventKind::Midi { 254 - channel: _, 255 - message, 256 - } => match message { 249 + if let TrackEventKind::Midi { 250 + channel: _, 251 + message, 252 + } = event.kind 253 + { 254 + match message { 257 255 MidiMessage::NoteOn { key, vel } | MidiMessage::NoteOff { key, vel } => { 258 256 stem_notes 259 257 .entry(absolute_tick_to_ms[tick] as u32) ··· 273 271 ); 274 272 } 275 273 _ => {} 276 - }, 277 - _ => {} 274 + } 278 275 } 279 276 progressbar.inc(1) 280 277 }
+1 -1
src/region.rs
··· 124 124 #[test] 125 125 fn test_sub_and_transate_coherence() { 126 126 let a = Region::from_origin(Point(3, 3)).unwrap(); 127 - let mut b = a.clone(); 127 + let mut b = a; 128 128 b.translate(2, 3); 129 129 130 130 assert_eq!(b - a, (2, 3));
+1 -3
src/transform.rs
··· 1 - use std::{ 2 - collections::{HashMap}, 3 - }; 1 + use std::collections::HashMap; 4 2 5 3 use slug::slugify; 6 4 use wasm_bindgen::prelude::*;
+1 -1
src/ui.rs
··· 18 18 pub fn start(verb: &'static str, message: &str) -> Self { 19 19 let spinner = ProgressBar::new(0).with_style( 20 20 ProgressStyle::with_template(&format_log_msg_cyan( 21 - &verb, 21 + verb, 22 22 &(message.to_owned() + " {spinner:.cyan}"), 23 23 )) 24 24 .unwrap(),
+2 -4
src/video.rs
··· 1 - use std::collections::HashMap; 2 1 use std::str::FromStr; 3 2 use std::{ 4 3 fmt::Formatter, ··· 7 6 path::{Path, PathBuf}, 8 7 }; 9 8 10 - use ffmpeg::{codec, format, media, Packet}; 11 - use ffmpeg_next::encoder; 12 9 extern crate ffmpeg_next as ffmpeg; 13 10 use anyhow::Result; 14 11 use chrono::{DateTime, NaiveDateTime}; ··· 609 606 Ok(()) 610 607 } 611 608 612 - fn add_audio_track(&mut self, output_file: String) -> Result<()> { 609 + #[allow(dead_code)] 610 + fn add_audio_track(&mut self, _output_file: String) -> Result<()> { 613 611 todo!("Look into https://github.com/zmwangx/rust-ffmpeg/blob/master/examples/transcode-x264.rs and maybe contribute to video-rs (see https://github.com/oddity-ai/video-rs/issues/44)"); 614 612 } 615 613 }