Ejercicios 63/94
This commit is contained in:
parent
5c4f61218f
commit
38cda643f7
|
@ -3,9 +3,7 @@
|
||||||
|
|
||||||
// Execute `rustlings hint generics1` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint generics1` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut shopping_list: Vec<?> = Vec::new();
|
let mut shopping_list: Vec<&str> = Vec::new();
|
||||||
shopping_list.push("milk");
|
shopping_list.push("milk");
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,12 @@
|
||||||
|
|
||||||
// Execute `rustlings hint generics2` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint generics2` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
struct Wrapper<T> {
|
||||||
|
value: T,
|
||||||
struct Wrapper {
|
|
||||||
value: u32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Wrapper {
|
impl<T> Wrapper<T> {
|
||||||
pub fn new(value: u32) -> Self {
|
pub fn new(value: T) -> Self {
|
||||||
Wrapper { value }
|
Wrapper { value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,14 @@
|
||||||
// implementing this trait.
|
// implementing this trait.
|
||||||
// Execute `rustlings hint traits1` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint traits1` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
trait AppendBar {
|
trait AppendBar {
|
||||||
fn append_bar(self) -> Self;
|
fn append_bar(self) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppendBar for String {
|
impl AppendBar for String {
|
||||||
// TODO: Implement `AppendBar` for type `String`.
|
fn append_bar(self) -> String {
|
||||||
|
format!("{}Bar", self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -11,13 +11,16 @@
|
||||||
// you can do this!
|
// you can do this!
|
||||||
// Execute `rustlings hint traits2` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint traits2` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
trait AppendBar {
|
trait AppendBar {
|
||||||
fn append_bar(self) -> Self;
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
// Consider what you can add to the Licensed trait.
|
// Consider what you can add to the Licensed trait.
|
||||||
// Execute `rustlings hint traits3` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint traits3` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
pub trait Licensed {
|
pub trait Licensed {
|
||||||
fn licensing_info(&self) -> String;
|
fn licensing_info(&self) -> String {
|
||||||
|
"Some information".to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SomeSoftware {
|
struct SomeSoftware {
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
// Don't change any line other than the marked one.
|
// Don't change any line other than the marked one.
|
||||||
// Execute `rustlings hint traits4` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint traits4` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
pub trait Licensed {
|
pub trait Licensed {
|
||||||
fn licensing_info(&self) -> String {
|
fn licensing_info(&self) -> String {
|
||||||
"some information".to_string()
|
"some information".to_string()
|
||||||
|
@ -20,7 +18,7 @@ impl Licensed for SomeSoftware {}
|
||||||
impl Licensed for OtherSoftware {}
|
impl Licensed for OtherSoftware {}
|
||||||
|
|
||||||
// YOU MAY ONLY CHANGE THE NEXT LINE
|
// 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()
|
software.licensing_info() == software_two.licensing_info()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
// Don't change any line other than the marked one.
|
// Don't change any line other than the marked one.
|
||||||
// Execute `rustlings hint traits5` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint traits5` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
pub trait SomeTrait {
|
pub trait SomeTrait {
|
||||||
fn some_function(&self) -> bool {
|
fn some_function(&self) -> bool {
|
||||||
true
|
true
|
||||||
|
@ -27,7 +25,7 @@ impl SomeTrait for OtherStruct {}
|
||||||
impl OtherTrait for OtherStruct {}
|
impl OtherTrait for OtherStruct {}
|
||||||
|
|
||||||
// YOU MAY ONLY CHANGE THE NEXT LINE
|
// 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()
|
item.some_function() && item.other_function()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue