Skip to content

Adding examples for CPU-intensive work section of chapter 6#263

Open
nt54hamnghi wants to merge 2 commits into
rust-lang:masterfrom
nt54hamnghi:nt54hamnghi/add-chap-6-examples
Open

Adding examples for CPU-intensive work section of chapter 6#263
nt54hamnghi wants to merge 2 commits into
rust-lang:masterfrom
nt54hamnghi:nt54hamnghi/add-chap-6-examples

Conversation

@nt54hamnghi
Copy link
Copy Markdown
Contributor

No description provided.

@nt54hamnghi nt54hamnghi force-pushed the nt54hamnghi/add-chap-6-examples branch from e6f43ed to 37b9c9c Compare May 12, 2026 02:22
Copy link
Copy Markdown
Member

@nrc nrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor suggestions, otherwise looks good, thanks!

Comment thread src/part-guide/io.md
async fn main() {
let contents = tokio::task::spawn_blocking(|| {
std::fs::read_to_string("file.txt").unwrap()
println!("{contents}");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable contents is not in scope here.

Comment thread src/part-guide/io.md
for i in 0..100_000_000 {
sum = sum.wrapping_add(i * i);
}
input * 42
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be in the loop or connected with sum?

Comment thread src/part-guide/io.md
// Use rayon's parallel iterators to compute the results in parallel
let results = data.into_par_iter().map(compute).collect::<Vec<_>>();
// Send the result back to Tokio.
send.send(results).expect("Failed to send results to Tokio");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use unwrap rather than expect here and elsewhere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants