Clean up clippy warnings
This commit is contained in:
parent
537fec8a4d
commit
489adc1af1
@ -12,7 +12,7 @@ impl Rgb {
|
|||||||
pub fn to_float_tuple(self) -> (f32, f32, f32) {
|
pub fn to_float_tuple(self) -> (f32, f32, f32) {
|
||||||
(f32::from(self.0), f32::from(self.1), f32::from(self.2))
|
(f32::from(self.0), f32::from(self.1), f32::from(self.2))
|
||||||
}
|
}
|
||||||
pub fn to_hex_str(&self) -> String {
|
pub fn to_hex_str(self) -> String {
|
||||||
format!("#{:02x}{:02x}{:02x}", self.0, self.1, self.2)
|
format!("#{:02x}{:02x}{:02x}", self.0, self.1, self.2)
|
||||||
}
|
}
|
||||||
// pub fn to_gamma_corrected_tuple(&self) -> (u8, u8, u8) {
|
// pub fn to_gamma_corrected_tuple(&self) -> (u8, u8, u8) {
|
||||||
@ -108,14 +108,14 @@ pub fn build_ramp(from_color: Rgb, to_color: Rgb, length: usize) -> Vec<Rgb> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn min_with_factor(at_least: u16, factor: u16) -> Result<u16, ()> {
|
pub fn min_with_factor(at_least: u16, factor: u16) -> Result<u16, ()> {
|
||||||
Ok(at_least
|
at_least
|
||||||
.checked_sub(1)
|
.checked_sub(1)
|
||||||
.ok_or(())?
|
.ok_or(())?
|
||||||
.div_euclid(factor)
|
.div_euclid(factor)
|
||||||
.checked_add(1)
|
.checked_add(1)
|
||||||
.ok_or(())?
|
.ok_or(())?
|
||||||
.checked_mul(factor)
|
.checked_mul(factor)
|
||||||
.ok_or(())?)
|
.ok_or(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
// Intentional code
|
// Intentional code
|
||||||
clippy::map_err_ignore,
|
clippy::map_err_ignore,
|
||||||
// "as f32" used frequently in this project
|
// "as f32" used frequently in this project
|
||||||
clippy::cast_precision_loss,
|
clippy::cast_precision_loss, clippy::cast_possible_truncation, clippy::cast_sign_loss,
|
||||||
// This is fine
|
// This is fine
|
||||||
clippy::implicit_return,
|
clippy::implicit_return,
|
||||||
// Missing docs is fine
|
// Missing docs is fine
|
||||||
|
@ -120,7 +120,7 @@ impl Parameters {
|
|||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn get_name(&self) -> &str {
|
pub const fn get_name(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
Self::Collide(_) => "Collide",
|
Self::Collide(_) => "Collide",
|
||||||
Self::Fade(_) => "Fade",
|
Self::Fade(_) => "Fade",
|
||||||
|
@ -57,9 +57,9 @@ impl Collide {
|
|||||||
pub fn new(params: &CollideParams) -> Self {
|
pub fn new(params: &CollideParams) -> Self {
|
||||||
Self {
|
Self {
|
||||||
num_lights: 0,
|
num_lights: 0,
|
||||||
left_color: params.left_color.clone(),
|
left_color: params.left_color,
|
||||||
right_color: params.right_color.clone(),
|
right_color: params.right_color,
|
||||||
conjoined_color: params.conjoined_color.clone(),
|
conjoined_color: params.conjoined_color,
|
||||||
step: 0,
|
step: 0,
|
||||||
step_max: 0,
|
step_max: 0,
|
||||||
conjoined_bounds: (0, 0),
|
conjoined_bounds: (0, 0),
|
||||||
|
@ -39,7 +39,7 @@ impl Default for Fade {
|
|||||||
impl Fade {
|
impl Fade {
|
||||||
pub fn new(params: &FadeParams) -> Self {
|
pub fn new(params: &FadeParams) -> Self {
|
||||||
Self {
|
Self {
|
||||||
color: params.color.clone(),
|
color: params.color,
|
||||||
step: 0,
|
step: 0,
|
||||||
direction: true,
|
direction: true,
|
||||||
num_lights: 1,
|
num_lights: 1,
|
||||||
|
@ -39,7 +39,7 @@ impl Default for MovingPixel {
|
|||||||
impl MovingPixel {
|
impl MovingPixel {
|
||||||
pub fn new(params: &MovingPixelParams) -> Self {
|
pub fn new(params: &MovingPixelParams) -> Self {
|
||||||
Self {
|
Self {
|
||||||
color: params.color.clone(),
|
color: params.color,
|
||||||
step: 0,
|
step: 0,
|
||||||
// TODO: Better initialization
|
// TODO: Better initialization
|
||||||
num_lights: 1,
|
num_lights: 1,
|
||||||
|
@ -79,21 +79,7 @@ impl Pattern for MovingRainbow {
|
|||||||
.saturating_mul(u16::try_from(RAINBOW.len()).or(Err(()))?);
|
.saturating_mul(u16::try_from(RAINBOW.len()).or(Err(()))?);
|
||||||
// The length of the buffer
|
// The length of the buffer
|
||||||
// Always a factor of length_factor
|
// Always a factor of length_factor
|
||||||
let buf_length = color::min_with_factor(num_lights, length_factor.into())?;
|
let buf_length = color::min_with_factor(num_lights, length_factor)?;
|
||||||
println!(
|
|
||||||
"Got buf length: {} with #lights {} and length factor {} ({})",
|
|
||||||
buf_length,
|
|
||||||
num_lights,
|
|
||||||
length_factor,
|
|
||||||
(self.width + self.skip) as usize * RAINBOW.len()
|
|
||||||
);
|
|
||||||
// num_lights
|
|
||||||
// .checked_sub(1)
|
|
||||||
// .ok_or(())?
|
|
||||||
// .div_euclid(length_factor)
|
|
||||||
// .checked_add(1)
|
|
||||||
// .ok_or(())?
|
|
||||||
// .saturating_mul(length_factor);
|
|
||||||
|
|
||||||
self.lights_buf = RAINBOW
|
self.lights_buf = RAINBOW
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -63,7 +63,7 @@ impl Orb {
|
|||||||
pub fn new(params: &OrbParams) -> Self {
|
pub fn new(params: &OrbParams) -> Self {
|
||||||
Self {
|
Self {
|
||||||
lights_buf: VecDeque::new(),
|
lights_buf: VecDeque::new(),
|
||||||
color: params.color.clone(),
|
color: params.color,
|
||||||
center_width: params.center_width,
|
center_width: params.center_width,
|
||||||
backoff_width: params.backoff_width,
|
backoff_width: params.backoff_width,
|
||||||
total_width: params
|
total_width: params
|
||||||
|
@ -37,7 +37,7 @@ impl Default for Solid {
|
|||||||
impl Solid {
|
impl Solid {
|
||||||
pub fn new(params: &SolidParams) -> Self {
|
pub fn new(params: &SolidParams) -> Self {
|
||||||
Self {
|
Self {
|
||||||
color: params.color.clone(),
|
color: params.color,
|
||||||
has_run: false,
|
has_run: false,
|
||||||
lights_buf: VecDeque::new(),
|
lights_buf: VecDeque::new(),
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::color::Rgb;
|
use crate::color::Rgb;
|
||||||
use crate::pattern::{FormRender, Parameters};
|
use crate::pattern::{FormRender, Parameters};
|
||||||
use askama;
|
|
||||||
|
|
||||||
#[derive(askama::Template, Clone, Debug, Default)]
|
#[derive(askama::Template, Clone, Debug, Default)]
|
||||||
#[template(path = "app.html", escape = "none")]
|
#[template(path = "app.html", escape = "none")]
|
||||||
@ -9,7 +8,7 @@ pub struct AppTemplate {
|
|||||||
}
|
}
|
||||||
impl live_view::Template for AppTemplate {
|
impl live_view::Template for AppTemplate {
|
||||||
fn render(&self) -> Result<String, Box<dyn std::error::Error>> {
|
fn render(&self) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
Ok(<Self as askama::Template>::render(&self)?)
|
Ok(<Self as askama::Template>::render(self)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
src/webui.rs
24
src/webui.rs
@ -1,4 +1,3 @@
|
|||||||
use crate::color::Rgb;
|
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
use crate::pattern;
|
use crate::pattern;
|
||||||
use crate::strip;
|
use crate::strip;
|
||||||
@ -78,23 +77,20 @@ async fn initial_load(_req: HttpRequest) -> impl Responder {
|
|||||||
..ControlTemplate::default()
|
..ControlTemplate::default()
|
||||||
}
|
}
|
||||||
.render()
|
.render()
|
||||||
.unwrap(),
|
.map_err(|e| {
|
||||||
..AppTemplate::default()
|
println!("Internal error e found: {:?}", e);
|
||||||
|
ErrorInternalServerError(e)
|
||||||
|
})?,
|
||||||
|
// ..AppTemplate::default()
|
||||||
};
|
};
|
||||||
state
|
state
|
||||||
.render()
|
.render()
|
||||||
.map(|b| HttpResponse::Ok().body(b))
|
.map(|b| HttpResponse::Ok().body(b))
|
||||||
.map_err(|e| ErrorInternalServerError(e))
|
.map_err(ErrorInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn start_socket(req: HttpRequest, stream: web::Payload) -> impl Responder {
|
async fn start_socket(req: HttpRequest, stream: web::Payload) -> impl Responder {
|
||||||
let mut live_view: LiveView<ControlTemplate> = LiveView::default();
|
let mut live_view: LiveView<ControlTemplate> = LiveView::default();
|
||||||
live_view.on_click("inc", |_event, state| {
|
|
||||||
state.color = Rgb(1_u8, 2_u8, 255_u8);
|
|
||||||
state.count += 1;
|
|
||||||
println!("Rendering color: {:?}", state.color);
|
|
||||||
Some(state.render().unwrap())
|
|
||||||
});
|
|
||||||
live_view.on_input("change-template", |event, state| {
|
live_view.on_input("change-template", |event, state| {
|
||||||
println!("Got change template ewvent: {:?}", event);
|
println!("Got change template ewvent: {:?}", event);
|
||||||
|
|
||||||
@ -103,7 +99,13 @@ async fn start_socket(req: HttpRequest, stream: web::Payload) -> impl Responder
|
|||||||
println!("Got params!: {:?}", params);
|
println!("Got params!: {:?}", params);
|
||||||
// state.selected_template = template_name.to_string();
|
// state.selected_template = template_name.to_string();
|
||||||
state.parameters = params;
|
state.parameters = params;
|
||||||
Some(state.render().unwrap())
|
state
|
||||||
|
.render()
|
||||||
|
.map_err(|e| {
|
||||||
|
format!("Error rendering state: {:?}", e);
|
||||||
|
e
|
||||||
|
})
|
||||||
|
.ok()
|
||||||
});
|
});
|
||||||
|
|
||||||
live_view.on_submit("form", |event, _state| {
|
live_view.on_submit("form", |event, _state| {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user