Ejercicios 63/94

This commit is contained in:
perro tuerto 2023-02-24 09:51:24 -08:00
parent 5c4f61218f
commit 38cda643f7
7 changed files with 19 additions and 24 deletions

View File

@ -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");
}

View File

@ -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<T> {
value: T,
}
impl Wrapper {
pub fn new(value: u32) -> Self {
impl<T> Wrapper<T> {
pub fn new(value: T) -> Self {
Wrapper { value }
}
}

View File

@ -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() {

View File

@ -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<String> {
fn append_bar(mut self) -> Vec<String> {
self.push(String::from("Bar"));
self
}
}
#[cfg(test)]
mod tests {

View File

@ -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 {

View File

@ -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()
}

View File

@ -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()
}