Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Rust Standard Library Cookbook

You're reading from   Rust Standard Library Cookbook Over 75 recipes to leverage the power of Rust

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher Packt
ISBN-13 9781788623926
Length 360 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Jan Hohenheim Jan Hohenheim
Author Profile Icon Jan Hohenheim
Jan Hohenheim
Daniel Durante Daniel Durante
Author Profile Icon Daniel Durante
Daniel Durante
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Learning the Basics FREE CHAPTER 2. Working with Collections 3. Handling Files and the Filesystem 4. Serialization 5. Advanced Data Structures 6. Handling Errors 7. Parallelism and Rayon 8. Working with Futures 9. Networking 10. Using Experimental Nightly Features 11. Other Books You May Enjoy

How to do it...

  1. Create a Rust project to work on during this chapter with cargo new chapter-seven.
  2. Navigate into the newly-created chapter-seven folder. For the rest of this chapter, we will assume that your command line is currently in this directory.
  3. Open the Cargo.toml file that has been generated for you.
  4. Under [dependencies], add the following line:
rayon = "1.0.0"

If you want, you can go to rayon's crates.io page (https://crates.io/crates/rayon) to check for the newest version and use that one instead.

  1. Inside the src folder, create a new folder called bin.
  2. Delete the generated lib.rs file, as we are not creating a library.
  3. In the src/bin folder, create a file called par_iter.rs.
  4. Add the following code and run it with cargo run --bin par_iter:
1  extern crate rayon;
2 use rayon::prelude::*;
3
4 fn main() {
5 let legend = "Did you ever hear the tragedy of Darth Plagueis
The Wise?";
6 let words: Vec<_> = legend.split_whitespace...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime