mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-02-12 04:39:19 +00:00
update from upstream
This commit is contained in:
parent
1d99518131
commit
87c44a3bc8
@ -9,10 +9,27 @@
|
|||||||
// Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = 1.2331f64;
|
let x = 1.2331f64;
|
||||||
let y = 1.2332f64;
|
let y = 1.2332f64;
|
||||||
if (x - y).abs() < 0.00001 {
|
if (x - y).abs() < 0.00001 {
|
||||||
println!("Success!");
|
println!("Success!");
|
||||||
}
|
}
|
||||||
|
=======
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
use std::f32;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let pi = 3.14f32;
|
||||||
|
let radius = 5.00f32;
|
||||||
|
|
||||||
|
let area = pi * f32::powi(radius, 2);
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"The area of a circle with radius {:.2} is {:.5}!",
|
||||||
|
radius, area
|
||||||
|
)
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,11 +24,18 @@ impl Default for Person {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
// Your task is to complete this implementation
|
// Your task is to complete this implementation
|
||||||
// in order for the line `let p = Person::from("Mark,20")` to compile
|
// in order for the line `let p = Person::from("Mark,20")` to compile
|
||||||
// Please note that you'll need to parse the age component into a `usize`
|
// Please note that you'll need to parse the age component into a `usize`
|
||||||
// with something like `"4".parse::<usize>()`. The outcome of this needs to
|
// with something like `"4".parse::<usize>()`. The outcome of this needs to
|
||||||
// be handled appropriately.
|
// be handled appropriately.
|
||||||
|
=======
|
||||||
|
// Your task is to complete this implementation in order for the line `let p =
|
||||||
|
// Person::from("Mark,20")` to compile Please note that you'll need to parse the
|
||||||
|
// age component into a `usize` with something like `"4".parse::<usize>()`. The
|
||||||
|
// outcome of this needs to be handled appropriately.
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
//
|
//
|
||||||
// Steps:
|
// Steps:
|
||||||
// 1. If the length of the provided string is 0, then return the default of
|
// 1. If the length of the provided string is 0, then return the default of
|
||||||
|
|||||||
@ -10,12 +10,20 @@
|
|||||||
// Execute `rustlings hint using_as` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint using_as` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
// The goal is to make sure that the division does not fail to compile
|
// The goal is to make sure that the division does not fail to compile
|
||||||
fn average(values: &[f64]) -> f64 {
|
fn average(values: &[f64]) -> f64 {
|
||||||
let total = values
|
let total = values
|
||||||
.iter()
|
.iter()
|
||||||
.fold(0.0, |a, b| a + b);
|
.fold(0.0, |a, b| a + b);
|
||||||
total / (values.len() as f64)
|
total / (values.len() as f64)
|
||||||
|
=======
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
fn average(values: &[f64]) -> f64 {
|
||||||
|
let total = values.iter().sum::<f64>();
|
||||||
|
total / values.len()
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@ -41,6 +41,7 @@ impl State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn process(&mut self, message: Message) {
|
fn process(&mut self, message: Message) {
|
||||||
|
<<<<<<< HEAD
|
||||||
// TODO: create a match expression to process the different message variants
|
// TODO: create a match expression to process the different message variants
|
||||||
match message {
|
match message {
|
||||||
Message::ChangeColor(r, g, b) => self.change_color((r, g, b)),
|
Message::ChangeColor(r, g, b) => self.change_color((r, g, b)),
|
||||||
@ -51,6 +52,12 @@ impl State {
|
|||||||
},
|
},
|
||||||
_ => self.quit(),
|
_ => self.quit(),
|
||||||
}
|
}
|
||||||
|
=======
|
||||||
|
// TODO: create a match expression to process the different message
|
||||||
|
// variants
|
||||||
|
// Remember: When passing a tuple as a function argument, you'll need
|
||||||
|
// extra parentheses: fn function((t, u, p, l, e))
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +75,11 @@ mod tests {
|
|||||||
};
|
};
|
||||||
state.process(Message::ChangeColor(255, 0, 255));
|
state.process(Message::ChangeColor(255, 0, 255));
|
||||||
state.process(Message::Echo(String::from("hello world")));
|
state.process(Message::Echo(String::from("hello world")));
|
||||||
|
<<<<<<< HEAD
|
||||||
state.process(Message::Move{ x: 10, y: 15 });
|
state.process(Message::Move{ x: 10, y: 15 });
|
||||||
|
=======
|
||||||
|
state.process(Message::Move(Point { x: 10, y: 15 }));
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
state.process(Message::Quit);
|
state.process(Message::Quit);
|
||||||
|
|
||||||
assert_eq!(state.color, (255, 0, 255));
|
assert_eq!(state.color, (255, 0, 255));
|
||||||
|
|||||||
@ -9,12 +9,23 @@
|
|||||||
// Execute `rustlings hint errors1` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint errors1` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
pub fn generate_nametag_text(name: String) -> Result<String, String> {
|
pub fn generate_nametag_text(name: String) -> Result<String, String> {
|
||||||
if name.len() > 0 {
|
if name.len() > 0 {
|
||||||
Ok(format!("Hi! My name is {}", name))
|
Ok(format!("Hi! My name is {}", name))
|
||||||
} else {
|
} else {
|
||||||
// Empty names aren't allowed.
|
// Empty names aren't allowed.
|
||||||
Err("`name` was empty; it must be nonempty.".into())
|
Err("`name` was empty; it must be nonempty.".into())
|
||||||
|
=======
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
pub fn generate_nametag_text(name: String) -> Option<String> {
|
||||||
|
if name.is_empty() {
|
||||||
|
// Empty names aren't allowed.
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(format!("Hi! My name is {}", name))
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,23 @@
|
|||||||
// functions2.rs
|
// functions2.rs
|
||||||
|
<<<<<<< HEAD
|
||||||
// Make me compile! Execute `rustlings hint functions2` for hints :)s
|
// Make me compile! Execute `rustlings hint functions2` for hints :)s
|
||||||
|
=======
|
||||||
|
//
|
||||||
|
// Execute `rustlings hint functions2` or use the `hint` watch subcommand for a
|
||||||
|
// hint.
|
||||||
|
|
||||||
|
// I AM NOT DONE
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
call_me(3);
|
call_me(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
fn call_me(num: i32) {
|
fn call_me(num: i32) {
|
||||||
|
=======
|
||||||
|
fn call_me(num:) {
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
for i in 0..num {
|
for i in 0..num {
|
||||||
println!("Ring! Call number {}", i + 1);
|
println!("Ring! Call number {}", i + 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,9 +6,17 @@
|
|||||||
// Execute `rustlings hint generics2` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint generics2` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
struct Wrapper<T> {
|
struct Wrapper<T> {
|
||||||
value: T
|
value: T
|
||||||
}
|
}
|
||||||
|
=======
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
struct Wrapper {
|
||||||
|
value: u32,
|
||||||
|
}
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
|
|
||||||
impl<T> Wrapper<T> {
|
impl<T> Wrapper<T> {
|
||||||
pub fn new(value: T) -> Self {
|
pub fn new(value: T) -> Self {
|
||||||
|
|||||||
@ -7,12 +7,15 @@ pub fn bigger(a: i32, b: i32) -> i32 {
|
|||||||
// Do not use:
|
// Do not use:
|
||||||
// - another function call
|
// - another function call
|
||||||
// - additional variables
|
// - additional variables
|
||||||
|
<<<<<<< HEAD
|
||||||
// Execute `rustlings hint if1` for hints
|
// Execute `rustlings hint if1` for hints
|
||||||
if (a > b) {
|
if (a > b) {
|
||||||
return a;
|
return a;
|
||||||
} else {
|
} else {
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
=======
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't mind this for now :)
|
// Don't mind this for now :)
|
||||||
|
|||||||
@ -5,7 +5,13 @@
|
|||||||
//
|
//
|
||||||
// Execute `rustlings hint if2` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint if2` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
pub fn fizz_if_foo(fizzish: &str) -> &str {
|
pub fn fizz_if_foo(fizzish: &str) -> &str {
|
||||||
|
=======
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
pub fn foo_if_fizz(fizzish: &str) -> &str {
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
if fizzish == "fizz" {
|
if fizzish == "fizz" {
|
||||||
"foo"
|
"foo"
|
||||||
} else if fizzish == "fuzz" {
|
} else if fizzish == "fuzz" {
|
||||||
|
|||||||
@ -3,6 +3,12 @@
|
|||||||
// Execute `rustlings hint macros4` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint macros4` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
macro_rules! my_macro {
|
macro_rules! my_macro {
|
||||||
() => {
|
() => {
|
||||||
println!("Check out my macro!");
|
println!("Check out my macro!");
|
||||||
|
|||||||
@ -4,7 +4,17 @@
|
|||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
mod sausage_factory {
|
mod sausage_factory {
|
||||||
|
<<<<<<< HEAD
|
||||||
pub fn make_sausage() {
|
pub fn make_sausage() {
|
||||||
|
=======
|
||||||
|
// Don't let anybody outside of this module see this!
|
||||||
|
fn get_secret_recipe() -> String {
|
||||||
|
String::from("Ginger")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_sausage() {
|
||||||
|
get_secret_recipe();
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
println!("sausage!");
|
println!("sausage!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,8 +8,14 @@
|
|||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
mod delicious_snacks {
|
mod delicious_snacks {
|
||||||
|
<<<<<<< HEAD
|
||||||
pub use self::fruits::PEAR as fruit;
|
pub use self::fruits::PEAR as fruit;
|
||||||
pub use self::veggies::CUCUMBER as veggie;
|
pub use self::veggies::CUCUMBER as veggie;
|
||||||
|
=======
|
||||||
|
// TODO: Fix these use statements
|
||||||
|
use self::fruits::PEAR as ???
|
||||||
|
use self::veggies::CUCUMBER as ???
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
|
|
||||||
mod fruits {
|
mod fruits {
|
||||||
pub const PEAR: &'static str = "Pear";
|
pub const PEAR: &'static str = "Pear";
|
||||||
|
|||||||
@ -9,7 +9,13 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
// Characters (`char`)
|
// Characters (`char`)
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
let my_first_initial: char = 'C';
|
let my_first_initial: char = 'C';
|
||||||
|
=======
|
||||||
|
// Note the _single_ quotes, these are different from the double quotes
|
||||||
|
// you've been seeing around.
|
||||||
|
let my_first_initial = 'C';
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
if my_first_initial.is_alphabetic() {
|
if my_first_initial.is_alphabetic() {
|
||||||
println!("Alphabetical!");
|
println!("Alphabetical!");
|
||||||
} else if my_first_initial.is_numeric() {
|
} else if my_first_initial.is_numeric() {
|
||||||
|
|||||||
@ -6,7 +6,20 @@
|
|||||||
// Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand
|
// Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand
|
||||||
// for a hint.
|
// for a hint.
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
fn main() {
|
fn main() {
|
||||||
let numbers = (1, 2, 3);
|
let numbers = (1, 2, 3);
|
||||||
println!("The second number is {}", numbers.1);
|
println!("The second number is {}", numbers.1);
|
||||||
|
=======
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn indexing_tuple() {
|
||||||
|
let numbers = (1, 2, 3);
|
||||||
|
// Replace below ??? with the tuple indexing syntax.
|
||||||
|
let second = ???;
|
||||||
|
|
||||||
|
assert_eq!(2, second,
|
||||||
|
"This is not the 2nd number in the tuple!")
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,8 +16,24 @@
|
|||||||
//
|
//
|
||||||
// Execute `rustlings hint quiz3` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint quiz3` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
pub fn times_two(num: i32) -> i32 {
|
pub fn times_two(num: i32) -> i32 {
|
||||||
num * 2
|
num * 2
|
||||||
|
=======
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
pub struct ReportCard {
|
||||||
|
pub grade: f32,
|
||||||
|
pub student_name: String,
|
||||||
|
pub student_age: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReportCard {
|
||||||
|
pub fn print(&self) -> String {
|
||||||
|
format!("{} ({}) - achieved a grade of {}",
|
||||||
|
&self.student_name, &self.student_age, &self.grade)
|
||||||
|
}
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -25,6 +41,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
<<<<<<< HEAD
|
||||||
fn returns_twice_of_positive_numbers() {
|
fn returns_twice_of_positive_numbers() {
|
||||||
assert_eq!(times_two(4), 8);
|
assert_eq!(times_two(4), 8);
|
||||||
}
|
}
|
||||||
@ -33,5 +50,31 @@ mod tests {
|
|||||||
fn returns_twice_of_negative_numbers() {
|
fn returns_twice_of_negative_numbers() {
|
||||||
// TODO write an assert for `times_two(-4)`
|
// TODO write an assert for `times_two(-4)`
|
||||||
assert_eq!(times_two(-4), -8);
|
assert_eq!(times_two(-4), -8);
|
||||||
|
=======
|
||||||
|
fn generate_numeric_report_card() {
|
||||||
|
let report_card = ReportCard {
|
||||||
|
grade: 2.1,
|
||||||
|
student_name: "Tom Wriggle".to_string(),
|
||||||
|
student_age: 12,
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
report_card.print(),
|
||||||
|
"Tom Wriggle (12) - achieved a grade of 2.1"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn generate_alphabetic_report_card() {
|
||||||
|
// TODO: Make sure to change the grade here after you finish the exercise.
|
||||||
|
let report_card = ReportCard {
|
||||||
|
grade: 2.1,
|
||||||
|
student_name: "Gary Plotter".to_string(),
|
||||||
|
student_age: 11,
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
report_card.print(),
|
||||||
|
"Gary Plotter (11) - achieved a grade of A+"
|
||||||
|
);
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,9 +45,15 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_structs() {
|
fn unit_structs() {
|
||||||
|
<<<<<<< HEAD
|
||||||
// TODO: Instantiate a unit struct!
|
// TODO: Instantiate a unit struct!
|
||||||
let unit_struct = UnitStruct;
|
let unit_struct = UnitStruct;
|
||||||
let message = format!("{:?}s are fun!", unit_struct);
|
let message = format!("{:?}s are fun!", unit_struct);
|
||||||
|
=======
|
||||||
|
// TODO: Instantiate a unit-like struct!
|
||||||
|
// let unit_like_struct =
|
||||||
|
let message = format!("{:?}s are fun!", unit_like_struct);
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
|
|
||||||
assert_eq!(message, "UnitLikeStructs are fun!");
|
assert_eq!(message, "UnitLikeStructs are fun!");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,8 +17,12 @@ struct Package {
|
|||||||
impl Package {
|
impl Package {
|
||||||
fn new(sender_country: String, recipient_country: String, weight_in_grams: i32) -> Package {
|
fn new(sender_country: String, recipient_country: String, weight_in_grams: i32) -> Package {
|
||||||
if weight_in_grams <= 0 {
|
if weight_in_grams <= 0 {
|
||||||
|
<<<<<<< HEAD
|
||||||
// Something goes here...
|
// Something goes here...
|
||||||
panic!("Package is lighter then air!")
|
panic!("Package is lighter then air!")
|
||||||
|
=======
|
||||||
|
panic!("Can not ship a weightless package.")
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
} else {
|
} else {
|
||||||
Package {
|
Package {
|
||||||
sender_country,
|
sender_country,
|
||||||
@ -33,9 +37,14 @@ impl Package {
|
|||||||
self.recipient_country != self.sender_country
|
self.recipient_country != self.sender_country
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
fn get_fees(&self, cents_per_kg: i32) -> i32 {
|
fn get_fees(&self, cents_per_kg: i32) -> i32 {
|
||||||
// Something goes here... (beware of grams to kg conversion)
|
// Something goes here... (beware of grams to kg conversion)
|
||||||
(self.weight_in_grams * cents_per_kg) / 100
|
(self.weight_in_grams * cents_per_kg) / 100
|
||||||
|
=======
|
||||||
|
fn get_fees(&self, cents_per_gram: i32) -> ??? {
|
||||||
|
// Something goes here...
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,8 +86,13 @@ mod tests {
|
|||||||
let sender_country = String::from("Spain");
|
let sender_country = String::from("Spain");
|
||||||
let recipient_country = String::from("Spain");
|
let recipient_country = String::from("Spain");
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
let cents_per_kg = 300;
|
let cents_per_kg = 300;
|
||||||
|
|
||||||
|
=======
|
||||||
|
let cents_per_gram = 3;
|
||||||
|
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
let package = Package::new(sender_country, recipient_country, 1500);
|
let package = Package::new(sender_country, recipient_country, 1500);
|
||||||
|
|
||||||
assert_eq!(package.get_fees(cents_per_gram), 4500);
|
assert_eq!(package.get_fees(cents_per_gram), 4500);
|
||||||
|
|||||||
@ -1,16 +1,17 @@
|
|||||||
// threads1.rs
|
// threads1.rs
|
||||||
//
|
// Make this compile! Execute `rustlings hint threads1` for hints :)
|
||||||
// This program spawns multiple threads that each run for at least 250ms, and
|
// The idea is the thread spawned on line 21 is completing jobs while the main thread is
|
||||||
// each thread returns how much time they took to complete. The program should
|
// monitoring progress until 10 jobs are completed. If you see 6 lines
|
||||||
// wait until all the spawned threads have finished and should collect their
|
// of "waiting..." and the program ends without timing out when running,
|
||||||
// return values into a vector.
|
// you've got it :)
|
||||||
//
|
|
||||||
// Execute `rustlings hint threads1` or use the `hint` watch subcommand for a
|
|
||||||
// hint.
|
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::Duration;
|
||||||
|
|
||||||
|
struct JobStatus {
|
||||||
|
jobs_completed: u32,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Introduce Mutex
|
// Introduce Mutex
|
||||||
|
|||||||
@ -7,14 +7,23 @@
|
|||||||
// Execute `rustlings hint traits1` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint traits1` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
trait AppendBar {
|
trait AppendBar {
|
||||||
fn append_bar(self) -> Self;
|
fn append_bar(self) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppendBar for String {
|
impl AppendBar for String {
|
||||||
|
<<<<<<< HEAD
|
||||||
fn append_bar(self) -> Self {
|
fn append_bar(self) -> Self {
|
||||||
self + "Bar"
|
self + "Bar"
|
||||||
}
|
}
|
||||||
|
=======
|
||||||
|
// TODO: Implement `AppendBar` for type `String`.
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@ -12,12 +12,16 @@ trait AppendBar {
|
|||||||
fn append_bar(self) -> Self;
|
fn append_bar(self) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
impl AppendBar for Vec<String> {
|
impl AppendBar for Vec<String> {
|
||||||
fn append_bar(mut self) -> Self {
|
fn append_bar(mut self) -> Self {
|
||||||
self.push(String::from("Bar"));
|
self.push(String::from("Bar"));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
=======
|
||||||
|
// TODO: Implement trait `AppendBar` for a vector of strings.
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|||||||
@ -4,8 +4,12 @@
|
|||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
<<<<<<< HEAD
|
||||||
let mut x = 3;
|
let mut x = 3;
|
||||||
println!("Number {}", x);
|
println!("Number {}", x);
|
||||||
x = 5; // don't change this line
|
x = 5; // don't change this line
|
||||||
|
=======
|
||||||
|
let x: i32;
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
println!("Number {}", x);
|
println!("Number {}", x);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,12 @@
|
|||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
<<<<<<< HEAD
|
||||||
let x: i32 = 256 * 256 * 256;
|
let x: i32 = 256 * 256 * 256;
|
||||||
|
=======
|
||||||
|
let x = 3;
|
||||||
|
println!("Number {}", x);
|
||||||
|
x = 5; // don't change this line
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
println!("Number {}", x);
|
println!("Number {}", x);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,8 +4,15 @@
|
|||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
<<<<<<< HEAD
|
||||||
let number = "3"; // don't change this line
|
let number = "3"; // don't change this line
|
||||||
println!("Number {}", number);
|
println!("Number {}", number);
|
||||||
let number = 3;
|
let number = 3;
|
||||||
println!("Number {}", number);
|
println!("Number {}", number);
|
||||||
|
=======
|
||||||
|
let number = "T-H-R-E-E"; // don't change this line
|
||||||
|
println!("Spell a Number : {}", number);
|
||||||
|
number = 3; // don't rename this variable
|
||||||
|
println!("Number plus two is : {}", number + 2);
|
||||||
|
>>>>>>> 11d8aea96f2c744d970ed1ffb38785cf5b511e5e
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user