From 0ac5f3a1e3f0580b5f52c2bfdd38dd650d74bec6 Mon Sep 17 00:00:00 2001 From: "David E. Perez Negron R." Date: Sat, 11 May 2024 11:44:39 -0600 Subject: [PATCH] traits done --- exercises/traits/traits1.rs | 4 +++- exercises/traits/traits2.rs | 7 ++++++- exercises/traits/traits3.rs | 5 +++-- exercises/traits/traits4.rs | 3 +-- exercises/traits/traits5.rs | 3 +-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/exercises/traits/traits1.rs b/exercises/traits/traits1.rs index 37dfcbf..361a147 100644 --- a/exercises/traits/traits1.rs +++ b/exercises/traits/traits1.rs @@ -7,7 +7,6 @@ // Execute `rustlings hint traits1` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE trait AppendBar { fn append_bar(self) -> Self; @@ -15,6 +14,9 @@ trait AppendBar { impl AppendBar for String { // TODO: Implement `AppendBar` for type `String`. + fn append_bar(self) -> Self { + format!("{self}Bar") + } } fn main() { diff --git a/exercises/traits/traits2.rs b/exercises/traits/traits2.rs index 3e35f8e..2908137 100644 --- a/exercises/traits/traits2.rs +++ b/exercises/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) -> Self { + self.push("Bar".to_string()); + self + } +} #[cfg(test)] mod tests { diff --git a/exercises/traits/traits3.rs b/exercises/traits/traits3.rs index 4e2b06b..0008d51 100644 --- a/exercises/traits/traits3.rs +++ b/exercises/traits/traits3.rs @@ -8,10 +8,11 @@ // Execute `rustlings hint traits3` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE pub trait Licensed { - fn licensing_info(&self) -> String; + fn licensing_info(&self) -> String{ + format!("Some information") + } } struct SomeSoftware { diff --git a/exercises/traits/traits4.rs b/exercises/traits/traits4.rs index 4bda3e5..0df0393 100644 --- a/exercises/traits/traits4.rs +++ b/exercises/traits/traits4.rs @@ -7,7 +7,6 @@ // Execute `rustlings hint traits4` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE pub trait Licensed { fn licensing_info(&self) -> String { @@ -23,7 +22,7 @@ impl Licensed for SomeSoftware {} impl Licensed for OtherSoftware {} // YOU MAY ONLY CHANGE THE NEXT LINE -fn compare_license_types(software: ??, software_two: ??) -> bool { +fn compare_license_types (software: T, software_two: U) -> bool { software.licensing_info() == software_two.licensing_info() } diff --git a/exercises/traits/traits5.rs b/exercises/traits/traits5.rs index df18380..bb3a462 100644 --- a/exercises/traits/traits5.rs +++ b/exercises/traits/traits5.rs @@ -7,7 +7,6 @@ // Execute `rustlings hint traits5` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE pub trait SomeTrait { fn some_function(&self) -> bool { @@ -30,7 +29,7 @@ impl SomeTrait for OtherStruct {} impl OtherTrait for OtherStruct {} // YOU MAY ONLY CHANGE THE NEXT LINE -fn some_func(item: ??) -> bool { +fn some_func(item: T) -> bool { item.some_function() && item.other_function() }