Add traits solutions

This commit is contained in:
David Bailey 2021-01-16 20:43:48 +00:00
parent 27545fe964
commit af9b7e1b08
2 changed files with 12 additions and 5 deletions
exercises/traits

View file

@ -8,14 +8,17 @@
// 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.push_str("Bar");
// self
// OR
format!("{}Bar", self)
}
}
fn main() {

View file

@ -10,13 +10,17 @@
// 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 {