From 961a9b9ceb9c105f02f6c02c75ae947a329d636b Mon Sep 17 00:00:00 2001 From: Emre AYDIN <aeaydin1@gmail.com> Date: Wed, 6 Jan 2021 18:11:22 +0300 Subject: [PATCH] Traits exercises complete --- exercises/traits/traits1.rs | 5 +++-- exercises/traits/traits2.rs | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/exercises/traits/traits1.rs b/exercises/traits/traits1.rs index 2ef9e11..72a1bf5 100644 --- a/exercises/traits/traits1.rs +++ b/exercises/traits/traits1.rs @@ -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() { diff --git a/exercises/traits/traits2.rs b/exercises/traits/traits2.rs index 916c3c4..291724a 100644 --- a/exercises/traits/traits2.rs +++ b/exercises/traits/traits2.rs @@ -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)]