Traits exercises complete
This commit is contained in:
parent
70824e2411
commit
961a9b9ceb
exercises/traits
|
@ -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() {
|
||||
|
|
|
@ -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)]
|
||||
|
|
Loading…
Reference in a new issue