finish traits exercises

This commit is contained in:
lukaszKielar 2020-06-30 20:24:22 +02:00
parent 2a9bd74176
commit 5a9d6a6677
2 changed files with 16 additions and 17 deletions
exercises/traits

View file

@ -8,14 +8,15 @@
// 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(mut self) -> Self {
self.push_str("Bar");
self
}
}
fn main() {
@ -40,5 +41,4 @@ mod tests {
String::from("BarBar")
);
}
}

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("Bar".to_string());
self
}
}
#[cfg(test)]
mod tests {
@ -31,5 +31,4 @@ mod tests {
assert_eq!(foo.pop().unwrap(), String::from("Bar"));
assert_eq!(foo.pop().unwrap(), String::from("Foo"));
}
}