Что я хочу:
struct Foo
{
const char * name;
};
void Bar(struct Foo * foo)
{
foo->name = "Name";
}
struct Foo<'a> {
name: &'a str
}
impl<'a> Foo<'a> {
fn bar(&self) {
self.name = "nm";
}
}
error[E0594]: cannot assign to `self.name` which is behind a `&` reference
--> src/main.rs:26:9
|
25 | fn bar(&self) {
| ----- help: consider changing this to be a mutable reference: `&mut self`
26 | self.name = "nm";
| ^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written
Пы Сы: В итоге, это должно быть так:
struct Foo<'a> {
name: &'a str
}
impl<'a> Foo<'a> {
fn bar(&mut self) {
self.name = "nm";
}
}