I am learning rust but I keep getting this error and I don't know how to solve it after spending time trying to solve it.
error[E0596]: cannot borrow data in a `&` reference as mutable
--> src/main.rs:72:13
|
72 | income_list.push( 1);
| ^^^^^^^^^^^ cannot borrow as mutable
I've used lazy_static in order to create a global varibale with type u64
:
lazy_static! {
static ref expense_list: Vec<i64> = Vec::new();
static ref income_list: Vec<u64> = Vec::new();
}
And I am trying to push value in it using the push()
function:
let mut income_input = String::new();
io::stdin().read_line(&mut income_input);
let mut income_input: u64 = match income_input.trim().parse() {
Ok(num) => num,
Err(_) => break,
};
income_list.push(1); // it was income_list.push(income_input)
I can't push any value in the vector as it will keep throwing me that error, as per my understanding a vector should be a kind of array without a fixed-size.
Where am I wrong ?