This doesn't compile. Why not?
The compiler is happy with the set_fred()
method, but not with
get_fred()
and get_fred_mut()
which reference the same Fred(String)
.
fn main() {
println!("Unable to compile enum impl methods with values");
}
enum Flintstone {
Fred(String),
Wilma(i32),
}
impl Flintstone {
fn set_fred(&mut self, fred: String) {
*self = Flintstone::Fred(fred);
}
// error[E0609]: no field `Fred` on type `Flintstone`
fn get_fred(self) -> String {
self.Fred
}
// error[E0609]: no field `Fred` on type `&mut Flintstone`
fn get_fred_mut(&mut self) -> &mut String {
&mut self.Fred
}
}