From 46060cf08fc02483cf22198532aa239f144b4404 Mon Sep 17 00:00:00 2001 From: Rock070 Date: Wed, 3 Jan 2024 00:16:38 +0800 Subject: [PATCH] Implement AppendBar trait for Vec --- exercises/15_traits/traits2.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/exercises/15_traits/traits2.rs b/exercises/15_traits/traits2.rs index 3e35f8e1..cdafcfd2 100644 --- a/exercises/15_traits/traits2.rs +++ b/exercises/15_traits/traits2.rs @@ -8,13 +8,18 @@ // // Execute `rustlings hint traits2` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE - trait AppendBar { fn append_bar(self) -> Self; } // TODO: Implement trait `AppendBar` for a vector of strings. +impl AppendBar for Vec { + fn append_bar(&mut self) -> Vec { + let vec = self.to_vec().push(String::from("Bar")); + + vec + } +} #[cfg(test)] mod tests {