Solve traits exercises

This commit is contained in:
Enrico Bozzolini 2020-06-08 21:38:59 +02:00
parent 8bc982ddb4
commit f25e8a6186
2 changed files with 9 additions and 9 deletions

View File

@ -8,14 +8,14 @@
// which appends "Bar" to any object
// implementing this trait.
// I AM NOT DONE
trait AppendBar {
fn append_bar(self) -> Self;
}
impl AppendBar for String {
//Add your code here
fn append_bar(self) -> Self {
self + "Bar"
}
}
fn main() {

View File

@ -10,16 +10,16 @@
// No boiler plate code this time,
// you can do this!
// I AM NOT DONE
trait AppendBar {
fn append_bar(self) -> Self;
}
//TODO: Add your code here
impl AppendBar for Vec<String> {
fn append_bar(mut self) -> Self {
self.push(String::from("Bar"));
self
}
}
#[cfg(test)]
mod tests {