mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-11-29 22:47:43 +02:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
pub fn bigger(a: i32, b: i32) -> i32 {
|
||||
// Complete this function to return the bigger number!
|
||||
// If both numbers are equal, any of them can be returned.
|
||||
// Do not use:
|
||||
// - another function call
|
||||
// - additional variables
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
fn main() {
|
||||
let vec0 = vec![22, 44, 66];
|
||||
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
let vec1 = fill_vec(vec0);
|
||||
|
||||
assert_eq!(vec0, vec![22, 44, 66]);
|
||||
assert_eq!(vec1, vec![22, 44, 66, 88]);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
fn main() {
|
||||
let vec0 = vec![22, 44, 66];
|
||||
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
let vec1 = fill_vec(vec0);
|
||||
|
||||
assert_eq!(vec1, vec![22, 44, 66, 88]);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
fn main() {
|
||||
let vec0 = vec![22, 44, 66];
|
||||
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
let vec1 = fill_vec(vec0);
|
||||
|
||||
assert_eq!(vec1, vec![22, 44, 66, 88]);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ fn trim_me(input: &str) -> String {
|
||||
}
|
||||
|
||||
fn compose_me(input: &str) -> String {
|
||||
// TODO: Add " world!" to the string! There's multiple ways to do this!
|
||||
// TODO: Add " world!" to the string! There are multiple ways to do this!
|
||||
???
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
// the form : "<team_1_name>,<team_2_name>,<team_1_goals>,<team_2_goals>"
|
||||
// Example: England,France,4,2 (England scored 4 goals, France 2).
|
||||
//
|
||||
// You have to build a scores table containing the name of the team, goals the
|
||||
// team scored, and goals the team conceded. One approach to build the scores
|
||||
// table is to use a Hashmap. The solution is partially written to use a
|
||||
// Hashmap, complete it to pass the test.
|
||||
// You have to build a scores table containing the name of the team, the total
|
||||
// number of goals the team scored, and the total number of goals the team
|
||||
// conceded. One approach to build the scores table is to use a Hashmap.
|
||||
// The solution is partially written to use a Hashmap,
|
||||
// complete it to pass the test.
|
||||
//
|
||||
// Make me pass the tests!
|
||||
//
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
pub fn factorial(num: u64) -> u64 {
|
||||
// Complete this function to return the factorial of num
|
||||
// Do not use:
|
||||
// - return
|
||||
// - early returns (using the `return` keyword explicitly)
|
||||
// Try not to use:
|
||||
// - imperative style loops (for, while)
|
||||
// - additional variables
|
||||
|
||||
@@ -27,22 +27,18 @@ impl Queue {
|
||||
}
|
||||
|
||||
fn send_tx(q: Queue, tx: mpsc::Sender<u32>) -> () {
|
||||
let qc = Arc::new(q);
|
||||
let qc1 = Arc::clone(&qc);
|
||||
let qc2 = Arc::clone(&qc);
|
||||
|
||||
thread::spawn(move || {
|
||||
for val in &qc1.first_half {
|
||||
for val in q.first_half {
|
||||
println!("sending {:?}", val);
|
||||
tx.send(*val).unwrap();
|
||||
tx.send(val).unwrap();
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
});
|
||||
|
||||
thread::spawn(move || {
|
||||
for val in &qc2.second_half {
|
||||
for val in q.second_half {
|
||||
println!("sending {:?}", val);
|
||||
tx.send(*val).unwrap();
|
||||
tx.send(val).unwrap();
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -24,8 +24,9 @@ impl Default for Person {
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
// Your task is to complete this implementation in order for the line `let p1 =
|
||||
// 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.
|
||||
//
|
||||
@@ -43,8 +44,7 @@ impl Default for Person {
|
||||
// I AM NOT DONE
|
||||
|
||||
impl From<&str> for Person {
|
||||
fn from(s: &str) -> Person {
|
||||
}
|
||||
fn from(s: &str) -> Person {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -127,14 +127,14 @@ mod tests {
|
||||
#[test]
|
||||
fn test_trailing_comma() {
|
||||
let p: Person = Person::from("Mike,32,");
|
||||
assert_eq!(p.name, "Mike");
|
||||
assert_eq!(p.age, 32);
|
||||
assert_eq!(p.name, "John");
|
||||
assert_eq!(p.age, 30);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trailing_comma_and_some_string() {
|
||||
let p: Person = Person::from("Mike,32,man");
|
||||
assert_eq!(p.name, "Mike");
|
||||
assert_eq!(p.age, 32);
|
||||
let p: Person = Person::from("Mike,32,dog");
|
||||
assert_eq!(p.name, "John");
|
||||
assert_eq!(p.age, 30);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
| error_handling | §9 |
|
||||
| generics | §10 |
|
||||
| traits | §10.2 |
|
||||
| tests | §11.1 |
|
||||
| lifetimes | §10.3 |
|
||||
| tests | §11.1 |
|
||||
| iterators | §13.2-4 |
|
||||
| threads | §16.1-3 |
|
||||
| smart_pointers | §15, §16.3 |
|
||||
| threads | §16.1-3 |
|
||||
| macros | §19.5 |
|
||||
| clippy | §21.4 |
|
||||
| conversions | n/a |
|
||||
|
||||
Reference in New Issue
Block a user