complete: traits

This commit is contained in:
seth 2021-06-23 16:53:55 +08:00
parent d1789a20c6
commit 6a31cb09bd
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) -> Self{
self + "Bar"
}
}
fn main() {

View file

@ -10,13 +10,18 @@
// 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> {
//Add your code here
fn append_bar(mut self) -> Self{
self.push(String::from("Bar"));
self
}
}
#[cfg(test)]
mod tests {