From f25e8a61862b1a521b941fdd96082bd0452310cd Mon Sep 17 00:00:00 2001 From: Enrico Bozzolini Date: Mon, 8 Jun 2020 21:38:59 +0200 Subject: [PATCH] Solve traits exercises --- exercises/traits/traits1.rs | 6 +++--- exercises/traits/traits2.rs | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/exercises/traits/traits1.rs b/exercises/traits/traits1.rs index 8253ef80..4cef7cd2 100644 --- a/exercises/traits/traits1.rs +++ b/exercises/traits/traits1.rs @@ -8,14 +8,14 @@ // 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() { diff --git a/exercises/traits/traits2.rs b/exercises/traits/traits2.rs index 7f5014d0..34b0ce29 100644 --- a/exercises/traits/traits2.rs +++ b/exercises/traits/traits2.rs @@ -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 { + fn append_bar(mut self) -> Self { + self.push(String::from("Bar")); + self + } +} #[cfg(test)] mod tests {