From 51c535c8ba70f1f1402f72a11b0eac077ba664fb Mon Sep 17 00:00:00 2001 From: young Date: Sat, 5 Nov 2022 18:08:09 +0900 Subject: [PATCH] traits2 --- exercises/traits/traits2.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/exercises/traits/traits2.rs b/exercises/traits/traits2.rs index 708bb19a..f051e4af 100644 --- a/exercises/traits/traits2.rs +++ b/exercises/traits/traits2.rs @@ -17,14 +17,20 @@ trait AppendBar { fn append_bar(self) -> Self; } -//TODO: Add your code here +impl AppendBar for Vec { + fn append_bar(self) -> Vec { + let mut _vec = self.clone(); + _vec.push(String::from("Bar")); + return _vec; + } +} #[cfg(test)] mod tests { use super::*; #[test] - fn is_vec_pop_eq_bar() { + fn is_vec_pop_eq_bar() { let mut foo = vec![String::from("Foo")].append_bar(); assert_eq!(foo.pop().unwrap(), String::from("Bar")); assert_eq!(foo.pop().unwrap(), String::from("Foo"));