Traits exercises complete

This commit is contained in:
Emre AYDIN 2021-01-06 18:11:22 +03:00
parent 70824e2411
commit 961a9b9ceb
2 changed files with 10 additions and 4 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(self) -> String {
format!("{}Bar", self)
}
}
fn main() {

View file

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