ENGLISH

Command-Line Rust: A Project-Based Primer for Writing Rust CLIs

Book information

Publisher
O'Reilly Media
Year
2022
ISBN
1098109430, 9781098109431
Language
english
Format
PDF
Filesize
2 MB (2316091 bytes)
Edition
1
Pages
396\310
Topic
Computers\\Programming: Programming Languages
Time added
2021-09-03 14:38:49

Description

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 programsWrite and test Rust programs and functionsRead and write files, including stdin, stdout, and stderrDocument and validate command-line argumentsWrite programs that fail gracefullyParse raw and delimited textUse and control randomness  This book is a great way to practice writing Rust in real-world scenarios. Ken has laid out a path to build your skills in testing, using crates, and solving common problems. -- Carol Nichols, Cofounder, Integer 32, co-author of The Rust Programming Language (NoStarch, 2018)   Many people who start tinkering with Rust struggle to know how to apply it to their day-to-day work. Command Line Rust is an excellent remedy to this. It shows you how to build utilities that can demonstrate to you and your colleagues that Rust is worth learning. -- Tim McNamara, author of Rust In Action (Manning, 2021) Preface What Is Rust (And Why Is Everybody Talkin’ About It)? Who Should Read This Book Why You Should Learn Rust The Coding Challenges Getting Rust and the Code Conventions Used in This Book Using Code Examples O’Reilly Online Learning How to Contact Us Acknowledgments 1. Truth Or Consequences Getting Started with “Hello, world!” Organizing a Rust Project Directory Creating and Running a Project with Cargo Writing and Running Integration Tests Adding a Project Dependency Understanding Program Exit Values Testing the Program Output Exit Values Make Programs Composable Summary 2. Test for Echo Starting a New Binary Program with Cargo How echo Works Getting Command-Line Arguments Adding clap as a Dependency Parsing Command-Line Arguments Using clap Creating the Program Output Integration and Unit Tests Creating the Test Output Files Comparing Program Output Using the Result Type Summary 3. On The Catwalk How cat Works Getting Started with Test-Driven Development Creating a Library Crate Defining the Parameters Processing the Files Opening a File or STDIN Solution Reading the Lines in a File Printing Line Numbers Going Further Summary 4. Head Aches How head Works Getting Started Parsing Strings into Numbers Converting Strings into Errors Defining the Arguments Processing the Input Files Reading Bytes versus Characters Solution Reading a File Line-by-line Preserving Line Endings While Reading a File Reading Bytes from a File Printing the File Separators Going Further Summary 5. Word To Your Mother How wc Works Getting Started Iterating the Files Solution Counting the Elements of a File or STDIN Formatting the Output Going Further Summary 6. Den of Uniquity How uniq Works Getting Started Defining the Arguments Testing the Program Solution Going Further Summary 7. Finders Keepers How find Works Getting Started Defining the Arguments Validating the Arguments Find All the Things Solution Going Further Summary 8. Shave and a Haircut How cut Works Getting Started Defining the Arguments Parsing the Position List Extracting Characters or Bytes Parsing Delimited Text Files Solution Going Further Summary 9. Jack the Grepper How grep Works Getting Started Defining the Arguments Finding the Files to Search Finding the Matching Lines of Input Solution Going Further Summary 10. Boston Commons How comm Works Getting Started Defining the Arguments Validating and Opening the Input Files Processing the Files Solution Going Further Summary 11. Epilogue

Similar books