Skip to content

Commit 822ce41

Browse files
committed
Fix clippy lints
1 parent fdabffd commit 822ce41

File tree

5 files changed

+58
-58
lines changed

5 files changed

+58
-58
lines changed

src/config.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl Config {
102102
.help("Colors for rendering the mesh using the Phong reflection model. Requires 3 colors as rgb hex values: ambient, diffuse, and specular. Defaults to blue.")
103103
.short('m')
104104
.long("material")
105-
.value_names(&["ambient","diffuse","specular"])
105+
.value_names(["ambient","diffuse","specular"])
106106
)
107107
.arg(
108108
clap::Arg::new("background")
@@ -138,17 +138,21 @@ impl Config {
138138
.expect("IMG_FILE not provided");
139139
match matches.get_one::<String>("format") {
140140
Some(x) => c.format = match_format(x),
141-
None => match Path::new(&c.img_filename).extension() {
142-
Some(ext) => c.format = match_format(ext.to_str().unwrap()),
143-
_ => (),
144-
},
141+
None => {
142+
if let Some(ext) = Path::new(&c.img_filename).extension() {
143+
c.format = match_format(ext.to_str().unwrap());
144+
}
145+
}
145146
};
146-
matches
147-
.get_one::<String>("size")
148-
.map(|x| c.width = x.parse::<u32>().expect("Invalid size"));
149-
matches
150-
.get_one::<String>("size")
151-
.map(|x| c.height = x.parse::<u32>().expect("Invalid size"));
147+
148+
if let Some(x) = matches.get_one::<String>("size") {
149+
c.width = x.parse::<u32>().expect("Invalid size");
150+
}
151+
152+
if let Some(x) = matches.get_one::<String>("size") {
153+
c.height = x.parse::<u32>().expect("Invalid size");
154+
}
155+
152156
c.visible = matches.contains_id("visible");
153157
c.verbosity = matches.get_count("verbosity") as usize;
154158
if let Some(materials) = matches.get_many::<String>("material") {
@@ -159,17 +163,16 @@ impl Config {
159163
specular: iter.next().unwrap_or([0.0, 0.0, 0.0]),
160164
};
161165
}
162-
matches
163-
.get_one::<String>("background")
164-
.map(|x| c.background = html_to_rgba(x));
165-
match matches.get_one::<String>("aamethod") {
166-
Some(x) => match x.as_str() {
166+
if let Some(x) = matches.get_one::<String>("background") {
167+
c.background = html_to_rgba(x);
168+
}
169+
if let Some(x) = matches.get_one::<String>("aamethod") {
170+
match x.as_str() {
167171
"none" => c.aamethod = AAMethod::None,
168172
"fxaa" => c.aamethod = AAMethod::FXAA,
169173
_ => unreachable!(),
170-
},
171-
None => (),
172-
};
174+
}
175+
}
173176
c.recalc_normals = matches.contains_id("recalc_normals");
174177

175178
c

src/fxaa.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ struct SpriteVertex {
3030
implement_vertex!(SpriteVertex, position, i_tex_coords);
3131

3232
impl FxaaSystem {
33-
pub fn new<F: ?Sized>(facade: &F) -> FxaaSystem
33+
pub fn new<F>(facade: &F) -> FxaaSystem
3434
where
35-
F: Facade,
35+
F: Facade + ?Sized,
3636
{
3737
FxaaSystem {
3838
context: facade.get_context().clone(),
@@ -63,7 +63,7 @@ impl FxaaSystem {
6363
index_buffer: glium::index::IndexBuffer::new(
6464
facade,
6565
glium::index::PrimitiveType::TriangleStrip,
66-
&[1 as u16, 2, 0, 3],
66+
&[1u16, 2, 0, 3],
6767
)
6868
.unwrap(),
6969

@@ -92,7 +92,7 @@ where
9292
let mut target_depth = system.target_depth.borrow_mut();
9393

9494
{
95-
let clear = if let &Some(ref tex) = &*target_color {
95+
let clear = if let Some(ref tex) = *target_color {
9696
tex.get_width() != target_dimensions.0
9797
|| tex.get_height().unwrap() != target_dimensions.1
9898
} else {
@@ -104,7 +104,7 @@ where
104104
}
105105

106106
{
107-
let clear = if let &Some(ref tex) = &*target_depth {
107+
let clear = if let Some(ref tex) = *target_depth {
108108
tex.get_dimensions() != target_dimensions
109109
} else {
110110
false
@@ -117,8 +117,8 @@ where
117117
if target_color.is_none() {
118118
let texture = glium::texture::Texture2d::empty(
119119
&system.context,
120-
target_dimensions.0 as u32,
121-
target_dimensions.1 as u32,
120+
target_dimensions.0,
121+
target_dimensions.1,
122122
)
123123
.unwrap();
124124
*target_color = Some(texture);
@@ -129,8 +129,8 @@ where
129129
let texture = glium::framebuffer::DepthRenderBuffer::new(
130130
&system.context,
131131
glium::texture::DepthFormat::I24,
132-
target_dimensions.0 as u32,
133-
target_dimensions.1 as u32,
132+
target_dimensions.0,
133+
target_dimensions.1,
134134
)
135135
.unwrap();
136136
*target_depth = Some(texture);
@@ -143,7 +143,7 @@ where
143143
);
144144

145145
let uniforms = uniform! {
146-
tex: &*target_color,
146+
tex: target_color,
147147
enabled: if enabled { 1i32 } else { 0i32 },
148148
resolution: (target_dimensions.0 as f32, target_dimensions.1 as f32)
149149
};

src/lib.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ const CAM_POSITION: cgmath::Point3<f32> = cgmath::Point3 {
3636
};
3737

3838
fn print_matrix(m: [[f32; 4]; 4]) {
39-
for i in 0..4 {
40-
debug!(
41-
"{:.3}\t{:.3}\t{:.3}\t{:.3}",
42-
m[i][0], m[i][1], m[i][2], m[i][3]
43-
);
39+
for row in &m {
40+
debug!("{:.3}\t{:.3}\t{:.3}\t{:.3}", row[0], row[1], row[2], row[3]);
4441
}
4542
debug!("");
4643
}
@@ -175,7 +172,7 @@ where
175172
let pixel_shader_src = include_str!("shaders/model.frag");
176173

177174
// TODO: Cache program binary
178-
let program = glium::Program::from_source(display, &vertex_shader_src, &pixel_shader_src, None);
175+
let program = glium::Program::from_source(display, vertex_shader_src, pixel_shader_src, None);
179176
let program = match program {
180177
Ok(p) => p,
181178
Err(glium::CompilationError(err, _)) => {
@@ -246,7 +243,7 @@ where
246243
target
247244
.draw(
248245
(&vertex_buf, &normal_buf),
249-
&indices,
246+
indices,
250247
&program,
251248
&uniforms,
252249
&params,
@@ -261,9 +258,8 @@ where
261258
let pixels: glium::texture::RawImage2d<u8> = texture.read();
262259
let img = image::ImageBuffer::from_raw(config.width, config.height, pixels.data.into_owned())
263260
.unwrap();
264-
let img = image::DynamicImage::ImageRgba8(img).flipv();
265261

266-
img
262+
image::DynamicImage::ImageRgba8(img).flipv()
267263
}
268264

269265
pub fn render_to_window(config: Config) -> Result<(), Box<dyn Error>> {
@@ -292,13 +288,14 @@ pub fn render_to_window(config: Config) -> Result<(), Box<dyn Error>> {
292288
.unwrap();
293289

294290
match ev {
295-
glutin::event::Event::WindowEvent { event, .. }
296-
if event == glutin::event::WindowEvent::CloseRequested =>
297-
{
291+
glutin::event::Event::WindowEvent {
292+
event: glutin::event::WindowEvent::CloseRequested,
293+
..
294+
} => {
298295
*control_flow = ControlFlow::Exit;
299296
return;
300297
}
301-
glutin::event::Event::NewEvents(cause) if cause == glutin::event::StartCause::Init => {
298+
glutin::event::Event::NewEvents(glutin::event::StartCause::Init) => {
302299
render_pipeline(&display, &config, &mesh, &mut framebuffer, &texture);
303300
}
304301
_ => (),
@@ -330,13 +327,11 @@ pub fn render_to_image(config: &Config) -> Result<image::DynamicImage, Box<dyn E
330327
// =========================
331328
let mesh = Mesh::load(&config.stl_filename, config.recalc_normals)?;
332329

333-
let img: image::DynamicImage;
334-
335330
// Create GL context
336331
// =================
337332
// 1. If not visible create a headless context.
338333
// 2. If headless context creation fails, create a normal context with a hidden window.
339-
match create_headless_display(&config) {
334+
let img: image::DynamicImage = match create_headless_display(config) {
340335
Ok(display) => {
341336
let texture = glium::Texture2d::empty(&display, config.width, config.height).unwrap();
342337
let depthtexture =
@@ -348,14 +343,14 @@ pub fn render_to_image(config: &Config) -> Result<image::DynamicImage, Box<dyn E
348343
&depthtexture,
349344
)
350345
.unwrap();
351-
img = render_pipeline(&display, &config, &mesh, &mut framebuffer, &texture);
346+
render_pipeline(&display, config, &mesh, &mut framebuffer, &texture)
352347
}
353348
Err(e) => {
354349
warn!(
355350
"Unable to create headless GL context. Trying hidden window instead. Reason: {:?}",
356351
e
357352
);
358-
let (display, _) = create_normal_display(&config)?;
353+
let (display, _) = create_normal_display(config)?;
359354
let texture = glium::Texture2d::empty(&display, config.width, config.height).unwrap();
360355
let depthtexture =
361356
glium::texture::DepthTexture2d::empty(&display, config.width, config.height)
@@ -366,15 +361,15 @@ pub fn render_to_image(config: &Config) -> Result<image::DynamicImage, Box<dyn E
366361
&depthtexture,
367362
)
368363
.unwrap();
369-
img = render_pipeline(&display, &config, &mesh, &mut framebuffer, &texture);
364+
render_pipeline(&display, config, &mesh, &mut framebuffer, &texture)
370365
}
371366
};
372367

373368
Ok(img)
374369
}
375370

376371
pub fn render_to_file(config: &Config) -> Result<(), Box<dyn Error>> {
377-
let img = render_to_image(&config)?;
372+
let img = render_to_image(config)?;
378373

379374
// Choose output
380375
// Write to stdout if user did not specify a file
@@ -438,6 +433,11 @@ pub fn render_to_file(config: &Config) -> Result<(), Box<dyn Error>> {
438433
///
439434
/// render_to_buffer(buf_ptr, width, height, stl_filename_c);
440435
/// ```
436+
///
437+
/// # Safety
438+
///
439+
/// * `buf_ptr` _must_ point to a valid initialized buffer, at least `width * height * 4` bytes long.
440+
/// * `stl_filename_c` must point to a valid null-terminated string.
441441
#[no_mangle]
442442
pub unsafe extern "C" fn render_to_buffer(
443443
buf_ptr: *mut u8,
@@ -476,8 +476,8 @@ pub unsafe extern "C" fn render_to_buffer(
476476
// Setup configuration for the renderer
477477
let config = Config {
478478
stl_filename: stl_filename_str.to_string(),
479-
width: width,
480-
height: height,
479+
width,
480+
height,
481481
..Default::default()
482482
};
483483

src/main.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ fn main() {
3333
error!("Application error: {}", e);
3434
process::exit(1);
3535
}
36-
} else {
37-
if let Err(e) = stl_thumb::render_to_file(&config) {
38-
error!("Application error: {}", e);
39-
process::exit(1);
40-
}
36+
} else if let Err(e) = stl_thumb::render_to_file(&config) {
37+
error!("Application error: {}", e);
38+
process::exit(1);
4139
}
4240
}
4341

src/mesh.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,7 @@ impl Mesh {
337337
let scale = 2.0 / longest;
338338
info!("Scale:\t{}", scale);
339339
let scale_matrix = cgmath::Matrix4::from_scale(scale);
340-
let matrix = scale_matrix * translation_matrix;
341-
matrix
340+
scale_matrix * translation_matrix
342341
}
343342
}
344343

0 commit comments

Comments
 (0)