From fc5403388fd083b43bc47e7f8053e4b5906f818b Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 10 Oct 2021 16:43:30 +0100 Subject: [PATCH] Use unstable Crate rustfmt option --- rustfmt.toml | 4 ++-- src/color.rs | 6 ++---- src/errors.rs | 3 +-- src/main.rs | 10 ++++++---- src/pattern.rs | 3 +-- src/pattern/collide.rs | 3 +-- src/pattern/fade.rs | 7 ++++--- src/pattern/moving_pixel.rs | 3 +-- src/pattern/moving_rainbow.rs | 8 +++++--- src/pattern/orb.rs | 7 ++++--- src/pattern/solid.rs | 3 +-- src/strip.rs | 25 ++++++++++++++----------- src/template.rs | 6 ++++-- src/ui.rs | 14 +++++++------- src/webui.rs | 17 +++++++++-------- 15 files changed, 62 insertions(+), 57 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index df9f698..5293560 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1,2 @@ -# unstable_features = true -# imports_granularity = "Crate" +unstable_features = true +imports_granularity = "Crate" diff --git a/src/color.rs b/src/color.rs index 4177d2a..5ece5a5 100644 --- a/src/color.rs +++ b/src/color.rs @@ -1,7 +1,5 @@ -use serde::Deserialize; -use serde::Serialize; -use std::num::ParseIntError; -use std::str::FromStr; +use serde::{Deserialize, Serialize}; +use std::{num::ParseIntError, str::FromStr}; #[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize, Default)] pub struct Rgb(pub u8, pub u8, pub u8); diff --git a/src/errors.rs b/src/errors.rs index c5834c8..b31f518 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,6 +1,5 @@ use core::any::Any; -use std::fmt; -use std::io; +use std::{fmt, io}; pub type ProgramResult = Result; diff --git a/src/main.rs b/src/main.rs index 7c1d45e..26cc3c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,10 +36,12 @@ mod template; mod ui; mod webui; use errors::{ProgramError, ProgramResult}; -use std::io; -use std::io::Write; -use std::sync::mpsc::{channel, Sender}; -use std::thread; +use std::{ + io, + io::Write, + sync::mpsc::{channel, Sender}, + thread, +}; use strip::LedStrip; use ui::console_ui_loop; diff --git a/src/pattern.rs b/src/pattern.rs index 060b86c..b2b2da3 100644 --- a/src/pattern.rs +++ b/src/pattern.rs @@ -1,7 +1,6 @@ use crate::color::Rgb; use serde::{Deserialize, Serialize}; use std::collections::vec_deque; -use std::iter; pub mod collide; pub mod fade; @@ -66,7 +65,7 @@ impl InputRender for Rgb { impl InputRender for Vec { fn render(&self, name: &str, _multi_index: Option) -> String { self.iter() - .chain(iter::once(&Rgb::default())) + // .chain(iter::once(&Rgb::default())) .enumerate() .fold(String::new(), |acc, (i, c)| { acc + &c.render(name, Some(i)) + "\n" diff --git a/src/pattern/collide.rs b/src/pattern/collide.rs index f22c7e6..e82d87b 100644 --- a/src/pattern/collide.rs +++ b/src/pattern/collide.rs @@ -1,8 +1,7 @@ use super::{FormRender, InputRender, Pattern}; use crate::color::{self, Rgb}; use serde::{Deserialize, Serialize}; -use std::collections::vec_deque; -use std::collections::VecDeque; +use std::collections::{vec_deque, VecDeque}; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct CollideParams { diff --git a/src/pattern/fade.rs b/src/pattern/fade.rs index 7215da0..4311e9b 100644 --- a/src/pattern/fade.rs +++ b/src/pattern/fade.rs @@ -1,9 +1,10 @@ use super::{FormRender, InputRender, Pattern}; use crate::color::{self, merge_colors_u8, Rgb}; use serde::{Deserialize, Serialize}; -use std::collections::vec_deque; -use std::collections::VecDeque; -use std::iter; +use std::{ + collections::{vec_deque, VecDeque}, + iter, +}; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct FadeParams { diff --git a/src/pattern/moving_pixel.rs b/src/pattern/moving_pixel.rs index a92ebc4..ef9395f 100644 --- a/src/pattern/moving_pixel.rs +++ b/src/pattern/moving_pixel.rs @@ -1,8 +1,7 @@ use super::{FormRender, InputRender, Pattern}; use crate::color::{self, Rgb}; use serde::{Deserialize, Serialize}; -use std::collections::vec_deque; -use std::collections::VecDeque; +use std::collections::{vec_deque, VecDeque}; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct MovingPixelParams { diff --git a/src/pattern/moving_rainbow.rs b/src/pattern/moving_rainbow.rs index cd93808..8914be2 100644 --- a/src/pattern/moving_rainbow.rs +++ b/src/pattern/moving_rainbow.rs @@ -1,9 +1,11 @@ use super::{FormRender, InputRender, Pattern}; use crate::color::{self, Rgb, RAINBOW}; use serde::{Deserialize, Serialize}; -use std::collections::{vec_deque, VecDeque}; -use std::convert::TryFrom; -use std::iter; +use std::{ + collections::{vec_deque, VecDeque}, + convert::TryFrom, + iter, +}; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct MovingRainbowParams { diff --git a/src/pattern/orb.rs b/src/pattern/orb.rs index 9e09eba..6002e66 100644 --- a/src/pattern/orb.rs +++ b/src/pattern/orb.rs @@ -1,9 +1,10 @@ use super::{FormRender, InputRender, Pattern}; use crate::color::{self, Rgb}; use serde::{Deserialize, Serialize}; -use std::collections::vec_deque; -use std::collections::VecDeque; -use std::iter; +use std::{ + collections::{vec_deque, VecDeque}, + iter, +}; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct OrbParams { diff --git a/src/pattern/solid.rs b/src/pattern/solid.rs index bbb01e5..94de18d 100644 --- a/src/pattern/solid.rs +++ b/src/pattern/solid.rs @@ -1,8 +1,7 @@ use super::{FormRender, InputRender, Pattern}; use crate::color::{self, Rgb}; use serde::{Deserialize, Serialize}; -use std::collections::vec_deque; -use std::collections::VecDeque; +use std::collections::{vec_deque, VecDeque}; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct SolidParams { diff --git a/src/strip.rs b/src/strip.rs index 8e2e33b..173fdf0 100644 --- a/src/strip.rs +++ b/src/strip.rs @@ -1,14 +1,17 @@ -use crate::color; -use crate::errors; -use crate::errors::ProgramError; -use crate::pattern::{self, Pattern}; -use std::cmp; -use std::ops::Add; -use std::process; -use std::sync::mpsc::{Receiver, Sender}; -use std::time::{Duration, Instant}; -use ws2818_rgb_led_spi_driver::adapter_gen::Ws28xxAdapter; -use ws2818_rgb_led_spi_driver::adapter_spi::Ws28xxSpiAdapter; +use crate::{ + color, errors, + errors::ProgramError, + pattern::{self, Pattern}, +}; +use std::{ + cmp, + ops::Add, + process, + sync::mpsc::{Receiver, Sender}, + thread, + time::{Duration, Instant}, +}; +use ws2818_rgb_led_spi_driver::{adapter_gen::Ws28xxAdapter, adapter_spi::Ws28xxSpiAdapter}; /// Maximum number of lights allowed const MAX_NUM_LIGHTS: u16 = 128; diff --git a/src/template.rs b/src/template.rs index 8606daa..af98b2a 100644 --- a/src/template.rs +++ b/src/template.rs @@ -1,5 +1,7 @@ -use crate::pattern::{FormRender, Parameters}; -use crate::strip; +use crate::{ + pattern::{FormRender, Parameters}, + strip, +}; use std::sync::{mpsc::Sender, Arc, Mutex}; #[derive(askama::Template, Clone, Debug, Default)] diff --git a/src/ui.rs b/src/ui.rs index aa2a9c6..e40e859 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,10 +1,10 @@ -use crate::color::Rgb; -use crate::errors::{self, ProgramError, ProgramResult}; -use crate::pattern::{self, Pattern}; -use crate::strip; -use std::io; -use std::io::Write; -use std::sync::mpsc::Sender; +use crate::{ + color::Rgb, + errors::{self, ProgramError, ProgramResult}, + pattern::{self, Pattern}, + strip, +}; +use std::{io, io::Write, sync::mpsc::Sender}; pub fn console_ui_loop( message_tx: &Sender, diff --git a/src/webui.rs b/src/webui.rs index a2d885a..c86b23b 100644 --- a/src/webui.rs +++ b/src/webui.rs @@ -1,20 +1,21 @@ -use crate::errors; -use crate::pattern; -use crate::strip; -use crate::template::{AppTemplate, ControlTemplate}; +use crate::{ + errors, pattern, strip, + template::{AppTemplate, ControlTemplate}, +}; use actix_web::HttpResponse; use actix_web_actors::ws; use live_view::{LiveView, StateSocket, Template}; -use actix_web::HttpRequest; use actix_web::{ error::{ErrorInternalServerError, JsonPayloadError, UrlencodedError}, get, post, web, web::JsonConfig, - App, HttpServer, Responder, Result, + App, HttpRequest, HttpServer, Responder, Result, +}; +use std::{ + io, + sync::{mpsc::Sender, Arc, Mutex}, }; -use std::io; -use std::sync::{mpsc::Sender, Arc, Mutex}; struct AppState { strip_tx: Arc>>,