From 38cda643f709229d2d46b039432be225e72a44f1 Mon Sep 17 00:00:00 2001 From: perro Date: Fri, 24 Feb 2023 09:51:24 -0800 Subject: [PATCH] Ejercicios 63/94 --- exercises/generics/generics1.rs | 4 +--- exercises/generics/generics2.rs | 10 ++++------ exercises/traits/traits1.rs | 6 +++--- exercises/traits/traits2.rs | 9 ++++++--- exercises/traits/traits3.rs | 6 +++--- exercises/traits/traits4.rs | 4 +--- exercises/traits/traits5.rs | 4 +--- 7 files changed, 19 insertions(+), 24 deletions(-) diff --git a/exercises/generics/generics1.rs b/exercises/generics/generics1.rs index 4c34ae4..e3ec91a 100644 --- a/exercises/generics/generics1.rs +++ b/exercises/generics/generics1.rs @@ -3,9 +3,7 @@ // Execute `rustlings hint generics1` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE - fn main() { - let mut shopping_list: Vec = Vec::new(); + let mut shopping_list: Vec<&str> = Vec::new(); shopping_list.push("milk"); } diff --git a/exercises/generics/generics2.rs b/exercises/generics/generics2.rs index aedbd55..ef08444 100644 --- a/exercises/generics/generics2.rs +++ b/exercises/generics/generics2.rs @@ -3,14 +3,12 @@ // Execute `rustlings hint generics2` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE - -struct Wrapper { - value: u32, +struct Wrapper { + value: T, } -impl Wrapper { - pub fn new(value: u32) -> Self { +impl Wrapper { + pub fn new(value: T) -> Self { Wrapper { value } } } diff --git a/exercises/traits/traits1.rs b/exercises/traits/traits1.rs index f5320a5..fe5bc7c 100644 --- a/exercises/traits/traits1.rs +++ b/exercises/traits/traits1.rs @@ -9,14 +9,14 @@ // implementing this trait. // Execute `rustlings hint traits1` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE - trait AppendBar { fn append_bar(self) -> Self; } impl AppendBar for String { - // TODO: Implement `AppendBar` for type `String`. + fn append_bar(self) -> String { + format!("{}Bar", self) + } } fn main() { diff --git a/exercises/traits/traits2.rs b/exercises/traits/traits2.rs index 288b498..4dec6a3 100644 --- a/exercises/traits/traits2.rs +++ b/exercises/traits/traits2.rs @@ -11,13 +11,16 @@ // you can do this! // 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 { + self.push(String::from("Bar")); + self + } +} #[cfg(test)] mod tests { diff --git a/exercises/traits/traits3.rs b/exercises/traits/traits3.rs index 6d2fd6c..7491a23 100644 --- a/exercises/traits/traits3.rs +++ b/exercises/traits/traits3.rs @@ -7,10 +7,10 @@ // Consider what you can add to the Licensed trait. // 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 { + "Some information".to_string() + } } struct SomeSoftware { diff --git a/exercises/traits/traits4.rs b/exercises/traits/traits4.rs index 6b54166..ab2d644 100644 --- a/exercises/traits/traits4.rs +++ b/exercises/traits/traits4.rs @@ -4,8 +4,6 @@ // Don't change any line other than the marked one. // 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 { "some information".to_string() @@ -20,7 +18,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: impl Licensed, software_two: impl Licensed) -> bool { software.licensing_info() == software_two.licensing_info() } diff --git a/exercises/traits/traits5.rs b/exercises/traits/traits5.rs index 0fbca28..b6378a1 100644 --- a/exercises/traits/traits5.rs +++ b/exercises/traits/traits5.rs @@ -4,8 +4,6 @@ // Don't change any line other than the marked one. // 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 { true @@ -27,7 +25,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: impl SomeTrait + OtherTrait) -> bool { item.some_function() && item.other_function() }