0%

For several consecutive years, Rust has been voted "most loved programming language" in Stack Overflow's annual developer survey. This open source systems programming language is now used for everything from game engines and operating systems to browser components and virtual reality simulation engines. But Rust is also an incredibly complex language with a notoriously difficult learning curve.

Rather than focus on the language as a whole, this guide teaches Rust using a single small, complete, focused program in each chapter. Author Ken Youens-Clark shows you how to start, write, and test each of these programs to create a finished product. You'll learn how to handle errors in Rust, read and write files, and use regular expressions, Rust types, structs, and more.

Discover how to:

  • Use Rust's standard libraries and data types such as strings, vectors, dictionaries, and sets to create systems programs
  • Write and test Rust programs and functions
  • Read and write files, including stdin, stdout, and stderr
  • Document and validate command-line arguments
  • Write programs that fail gracefully
  • Parse raw and delimited text as well as Excel data
  • Use and control randomness

Table of Contents

  1. Preface
    1. What Is Rust (And Why Is Everybody Talkin’ About It)?
    2. Who Should Read This Book
    3. Why You Should Learn Rust
    4. The Coding Challenges
    5. Getting Rust and the Code
    6. Conventions Used in This Book
    7. Using Code Examples
    8. O’Reilly Online Learning
    9. How to Contact Us
    10. Acknowledgments
  2. 1. Truth Or Consequences
    1. Getting Started with “Hello, world!”
    2. Organizing a Rust Project Directory
    3. Creating and Running a Project with Cargo
    4. Writing and Running Integration Tests
    5. Adding a Project Dependency
    6. Understanding Program Exit Values
    7. Testing the Program Output
    8. Exit Values Make Programs Composable
    9. Summary
  3. 2. Test for Echo
    1. Starting a New Binary Program with Cargo
    2. How echo Works
    3. Getting Command-Line Arguments
    4. Adding clap as a Dependency
    5. Parsing Command-Line Arguments Using clap
    6. Creating the Program Output
    7. Integration and Unit Tests
    8. Creating the Test Output Files
    9. Comparing Program Output
    10. Using the Result Type
    11. Summary
  4. 3. On The Catwalk
    1. How cat Works
    2. Getting Started with Test-Driven Development
    3. Creating a Library Crate
    4. Defining the Parameters
    5. Processing the Files
    6. Opening a File or STDIN
    7. Solution
    8. Reading the Lines in a File
    9. Printing Line Numbers
    10. Going Further
    11. Summary
  5. 4. Head Aches
    1. How head Works
    2. Getting Started
    3. Parsing Strings into Numbers
    4. Converting Strings into Errors
    5. Defining the Arguments
    6. Processing the Input Files
    7. Reading Bytes versus Characters
    8. Solution
    9. Reading a File Line-by-line
    10. Preserving Line Endings While Reading a File
    11. Reading Bytes from a File
    12. Printing the File Separators
    13. Going Further
    14. Summary
  6. 5. Word To Your Mother
    1. How wc Works
    2. Getting Started
    3. Iterating the Files
    4. Solution
    5. Counting the Elements of a File or STDIN
    6. Formatting the Output
    7. Going Further
    8. Summary
  7. 6. Den of Uniquity
    1. How uniq Works
    2. Getting Started
    3. Defining the Arguments
    4. Testing the Program
    5. Solution
    6. Going Further
    7. Summary
  8. 7. Finders Keepers
    1. How find Works
    2. Getting Started
    3. Defining the Arguments
    4. Validating the Arguments
    5. Find All the Things
    6. Solution
    7. Going Further
    8. Summary
  9. 8. Shave and a Haircut
    1. How cut Works
    2. Getting Started
    3. Defining the Arguments
    4. Parsing the Position List
    5. Extracting Characters or Bytes
    6. Parsing Delimited Text Files
    7. Solution
    8. Going Further
    9. Summary
  10. 9. Jack the Grepper
    1. How grep Works
    2. Getting Started
    3. Defining the Arguments
    4. Finding the Files to Search
    5. Finding the Matching Lines of Input
    6. Solution
    7. Going Further
    8. Summary
  11. 10. Boston Commons
    1. How comm Works
    2. Getting Started
    3. Defining the Arguments
    4. Validating and Opening the Input Files
    5. Processing the Files
    6. Solution
    7. Going Further
    8. Summary
  12. 11. Epilogue
35.171.159.141