I'm working on the traits2.rs exercise in rustlings and am confused on Rust's syntax for traits. I have the following working solution (that compiles and passes the test, I'm using Rust 1.50):
trait AppendBar {
fn append_bar(self) -> Self;
}
impl AppendBar for Vec<String> {
fn append_bar(mut self) -> Self {
self.push("Bar".into());
self
}
}
However, I'm confused that, while the trait definition is fn append_bar(self) -> Self, my implementation for it is fn append_bar(mut self) -> Self, which has an additional mut on the signature. Why is this allowed?