Yeah, the spelling gets me. I've added doc aliases:
got my first encode to generate a correct PNG file but cargo gave me warnings..Can I ignore them ?
D6204 ~/PNG $cargo run
Compiling PNG v0.1.0 (/home/D6204/PNG)
warning: crate PNG
should have a snake case name
|
= note: #[warn(non_snake_case)]
on by default
= help: convert the identifier to snake case: png
warning: unused std::result::Result
that must be used
--> src/main.rs:17:1
|
17 | encode32_file("out.png", &img, W, H) ;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(unused_must_use)]
on by default
= note: this Result
may be an Err
variant, which should be handled
Finished dev [unoptimized + debuginfo] target(s) in 0.58s
Running `target/debug/PNG`
out.png !
D6204 ~/PNG $
Well, they're not errors, so you can ignore them. Generally better to correct them though...
The first is about naming conventions.
The second means that encode32_file()
could fail, and you should probably handle that case instead of ignoring the failure (even if "handling it" means explicitily ignoring it in your code). Ignoring these is a bug often enough that it's common to forbid the warning.
Side note: You can put your compiler output into```text blocks to make it easier to read.
You're expected to handle errors, e.g.
if let Err(e) = encode32_file(…) {
eprintln!("oops! {}", e);
return;
}
See ?
(try) operator to remove boilerplate.
Rust also has its style/naming conventions that it will nudge you towards. See also cargo clippy
.
Thanks ! I'm just starting to get into Rust`s way of handling errors .. Some of my C++ habits are leading me to do some bad Rust coding..
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.