Hi all,
I'm working on a simple CLI to track and update TODOs as a way of learning Rust.
I'm very new, but this is some unexpected behaviour that has me stumped.
I want to push a new task into my Tasks items vector, but when I do so and attempt to print the result
all that's printed is ()
?
//! Trying to push to the vector of a struct
#![deny(warnings)]
// Struct containing a vector of tasks
#[derive(Debug)]
struct Tasks {
items: Vec<Task>,
}
// Individual task structs; want to add one of these to Tasks.items
#[derive(Clone, Debug)]
struct Task {
id: String,
field: String,
status: String,
}
fn main() {
// Defining existing tasks
let mut tasks = Tasks {
items:
[
Task {
id: "todo1".to_string(),
field: "something to do one".to_string(),
status: "done".to_string()
},
Task {
id: "todo2".to_string(),
field: "something to do too".to_string(),
status: "in progress".to_string()
}
].to_vec()
};
//creating a new task
let entry = Task { id: "1".to_string(), field: "Adding a new task to the list".to_string(), status: "in progress".to_string() };
println!("{:?}", tasks.items.push(entry)); // prints `()` and I don't understand why?
}
Output:
()
Errors:
Compiling playground v0.0.1 (/playground)
Finished dev [unoptimized + debuginfo] target(s) in 0.80s
Running `target/debug/playground`
I have a feeling it's something simple but couldn't find any existing threads/documentation about it, any help is super appreciated !