Mut
Published .. 13-09-2024
Type ....... article
Tags .......
Type ....... article
Tags .......
If a value is mutable it must be declared with mut.
But beware, the pointer madness it not all gone.
Lets say you want to find a customer in a list and be able to mutate this customer:
fn (mut tm Timemanager) find_customer(id string) ?&Customer {
for mut c in tm.customers {
if c.id == id {
return c
}
}
return none
}
Even though c is declared as mut , you must return a pointer from the function to be able to mutate c outside this function. And there is no warning if you do not.
Its not possible to use mut in the return type declaration.