I am a big believer in the idea that learning comes best when one is involved in doing. I've been working through various resources, searching terms on Google, asking lots of questions on this forum, & etc, and will, of course, continue those practices as I continue to learn the Rust programming language. As with my students when I was a high school math teacher, the concepts behind the mechanics we teach often don't get learned until the student has been using the mechanics for a while. So, I have started working on my pet project and am hoping that some of those strange & fuzzy concepts that seem so simple to experienced programmers will eventually come clear. (Note: Some attempts to address my questions below were posted on this thread, but it all is still quite fuzzy and mysterious to me anyway.)
Here is my beginning code:
#[derive(Debug)]
struct Variable {
var_name: String,
is_num: bool,
is_list: bool,
}
struct Question {
qtext: String,
var_vec: Vec<Variable>,
answer: String, // A numeric answer will need to be converted into a string.
}
fn main() {
let var1 = Variable {
var_name: "num1".to_string(),
is_num: true,
is_list: false,
};
let var2 = Variable {
var_name: "num2".to_string(),
is_num: true,
is_list: false,
};
let varvec = vec![var1, var2];
let q1 = Question {
qtext: String::from("What is ~~num1~~ plus ~~num2~~?"),
var_vec: varvec,
answer: String::from("To be calculated"),
};
println!("\n Question: {}", q1.qtext);
println!("\n Variable vector: {:?}", q1.var_vec);
println!("\n Answer: {}", q1.answer);
println!("\n ");
}
This code works and does what I expected, but I get warnings that are just plain annoying. I'm sure that the problem orbits the fact that I really don't understand "attributes" or "debug" or the line #[derive(Debug)]
, but hopefully that understanding will come to me later. Right now I just want to get rid of these annoying warnings.
Here's what the compiler kicks out:
warning: fields `var_name`, `is_num` and `is_list` are never read
--> src/main.rs:8:5
|
7 | struct Variable {
| -------- fields in this struct
8 | var_name: String,
| ^^^^^^^^^^^^^^^^
9 | is_num: bool,
| ^^^^^^^^^^^^
10 | is_list: bool,
| ^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
= note: `Variable` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
I really don't know what the compiler is complaining about, but what I really want to know is how do I get rid of these warnings???
Thanks for your help.