arc and moo cow
This commit is contained in:
@@ -21,19 +21,17 @@
|
|||||||
//
|
//
|
||||||
// Execute `rustlings hint arc1` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint arc1` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
#![forbid(unused_imports)] // Do not change this, (or the next) line.
|
#![forbid(unused_imports)] // Do not change this, (or the next) line.
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let numbers: Vec<_> = (0..100u32).collect();
|
let numbers: Vec<_> = (0..100u32).collect();
|
||||||
let shared_numbers = // TODO
|
let shared_numbers = Arc::new(numbers); // TODO
|
||||||
let mut joinhandles = Vec::new();
|
let mut joinhandles = Vec::new();
|
||||||
|
|
||||||
for offset in 0..8 {
|
for offset in 0..8 {
|
||||||
let child_numbers = // TODO
|
let child_numbers = Arc::clone(&shared_numbers); // TODO
|
||||||
joinhandles.push(thread::spawn(move || {
|
joinhandles.push(thread::spawn(move || {
|
||||||
let sum: u32 = child_numbers.iter().filter(|&&n| n % 8 == offset).sum();
|
let sum: u32 = child_numbers.iter().filter(|&&n| n % 8 == offset).sum();
|
||||||
println!("Sum of offset {} is {}", offset, sum);
|
println!("Sum of offset {} is {}", offset, sum);
|
||||||
|
|||||||
@@ -12,8 +12,6 @@
|
|||||||
//
|
//
|
||||||
// Execute `rustlings hint cow1` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint cow1` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
fn abs_all<'a, 'b>(input: &'a mut Cow<'b, [i32]>) -> &'a mut Cow<'b, [i32]> {
|
fn abs_all<'a, 'b>(input: &'a mut Cow<'b, [i32]>) -> &'a mut Cow<'b, [i32]> {
|
||||||
@@ -49,6 +47,8 @@ mod tests {
|
|||||||
let mut input = Cow::from(&slice[..]);
|
let mut input = Cow::from(&slice[..]);
|
||||||
match abs_all(&mut input) {
|
match abs_all(&mut input) {
|
||||||
// TODO
|
// TODO
|
||||||
|
Cow::Borrowed(_) => Ok(()),
|
||||||
|
_ => Err("Expected a reference I suppose?"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +61,8 @@ mod tests {
|
|||||||
let mut input = Cow::from(slice);
|
let mut input = Cow::from(slice);
|
||||||
match abs_all(&mut input) {
|
match abs_all(&mut input) {
|
||||||
// TODO
|
// TODO
|
||||||
|
Cow::Owned(_) => Ok(()),
|
||||||
|
_ => Err("Expected owned value"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +75,8 @@ mod tests {
|
|||||||
let mut input = Cow::from(slice);
|
let mut input = Cow::from(slice);
|
||||||
match abs_all(&mut input) {
|
match abs_all(&mut input) {
|
||||||
// TODO
|
// TODO
|
||||||
|
Cow::Owned(_) => Ok(()),
|
||||||
|
_ => Err("Expected owned value"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user