finish traits exercises
This commit is contained in:
parent
2a9bd74176
commit
5a9d6a6677
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(mut self) -> Self {
|
||||
self.push_str("Bar");
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -40,5 +41,4 @@ mod tests {
|
|||
String::from("BarBar")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue