Update cookies preferences

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

3.82/5 (71 ratings by Goodreads)
  • Format: 402 pages
  • Pub. Date: 13-Jan-2022
  • Publisher: O'Reilly Media
  • Language: eng
  • ISBN-13: 9781098109387
  • Format - EPUB+DRM
  • Price: 47,96 €*
  • * the price is final i.e. no additional discount will apply
  • Add to basket
  • Add to Wishlist
  • This ebook is for personal use only. E-Books are non-refundable.
  • Format: 402 pages
  • Pub. Date: 13-Jan-2022
  • Publisher: O'Reilly Media
  • Language: eng
  • ISBN-13: 9781098109387

DRM restrictions

  • Copying (copy/paste):

    not allowed

  • Printing:

    not allowed

  • Usage:

    Digital Rights Management (DRM)
    The publisher has supplied this book in encrypted form, which means that you need to install free software in order to unlock and read it.  To read this e-book you have to create Adobe ID More info here. Ebook can be read and downloaded up to 6 devices (single user with the same Adobe ID).

    Required software
    To read this ebook on a mobile device (phone or tablet) you'll need to install this free app: PocketBook Reader (iOS / Android)

    To download and read this eBook on a PC or Mac you need Adobe Digital Editions (This is a free app specially developed for eBooks. It's not the same as Adobe Reader, which you probably already have on your computer.)

    You can't read this ebook with Amazon Kindle

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 focusing 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 numbers, strings, vectors, structs, Options, and Results to create command-line 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 manually, using regular expressions and Rust crates
  • Use and control randomness

Preface ix
1 Truth or Consequences
1(16)
Getting Started with "Hello, world!"
1(2)
Organizing a Rust Project Directory
3(1)
Creating and Running a Project with Cargo
4(2)
Writing and Running Integration Tests
6(10)
Adding a Project Dependency
10(1)
Understanding Program Exit Values
11(3)
Testing the Program Output
14(1)
Exit Values Make Programs Composable
15(1)
Summary
16(1)
2 Test for Echo
17(26)
How echo Works
17(3)
Getting Started
20(13)
Accessing the Command-Line Arguments
21(3)
Adding clap as a Dependency
24(1)
Parsing Command-Line Arguments Using clap
25(4)
Creating the Program Output
29(4)
Writing Integration Tests
33(8)
Creating the Test Output Files
34(1)
Comparing Program Output
35(1)
Using the Result Type
36(5)
Summary
41(2)
3 On the Catwalk
43(26)
How cat Works
44(4)
Getting Started
48(15)
Starting with Tests
48(2)
Creating a Library Crate
50(1)
Defining the Parameters
51(5)
Iterating Through the File Arguments
56(1)
Opening a File or STDIN
56(3)
Using the Test Suite
59(4)
Solution
63(4)
Reading the Lines in a File
63(1)
Printing Line Numbers
64(3)
Going Further
67(1)
Summary
67(2)
4 Head Aches
69(26)
How head Works
70(3)
Getting Started
73(13)
Writing a Unit Test to Parse a String into a Number
75(2)
Converting Strings into Errors
77(3)
Defining the Arguments
80(3)
Processing the Input Files
83(2)
Reading Bytes Versus Characters
85(1)
Solution
86(6)
Reading a File Line by Line
86(1)
Preserving Line Endings While Reading a File
86(2)
Reading Bytes from a File
88(3)
Printing the File Separators
91(1)
Going Further
92(1)
Summary
92(3)
5 Word to Your Mother
95(24)
How wc Works
95(5)
Getting Started
100(9)
Iterating the Files
105(1)
Writing and Testing a Function to Count File Elements
106(3)
Solution
109(8)
Counting the Elements of a File or STDIN
109(2)
Formatting the Output
111(6)
Going Further
117(1)
Summary
117(2)
6 Den of Uniquity
119(22)
How uniq Works
119(5)
Getting Started
124(10)
Defining the Arguments
125(4)
Testing the Program
129(4)
Processing the Input Files
133(1)
Solution
134(6)
Going Further
140(1)
Summary
140(1)
7 Finders Keepers
141(28)
How find Works
142(4)
Getting Started
146(11)
Defining the Arguments
147(6)
Validating the Arguments
153(2)
Finding All the Things
155(2)
Solution
157(6)
Conditionally Testing on Unix Versus Windows
163(3)
Going Further
166(1)
Summary
167(2)
8 Shave and a Haircut
169(32)
How cut Works
169(5)
Getting Started
174(17)
Defining the Arguments
175(6)
Parsing the Position List
181(6)
Extracting Characters or Bytes
187(2)
Parsing Delimited Text Files
189(2)
Solution
191(7)
Selecting Characters from a String
191(2)
Selecting Bytes from a String
193(2)
Selecting Fields from a csv::StringRecord
195(1)
Final Boss
196(2)
Going Further
198(1)
Summary
198(3)
9 Jack the Grepper
201(24)
How grep Works
202(3)
Getting Started
205(14)
Defining the Arguments
206(6)
Finding the Files to Search
212(3)
Finding the Matching Lines of Input
215(4)
Solution
219(4)
Going Further
223(1)
Summary
224(1)
10 Boston Commons
225(20)
How comm Works
225(4)
Getting Started
229(7)
Defining the Arguments
229(4)
Validating and Opening the Input Files
233(2)
Processing the Files
235(1)
Solution
236(8)
Going Further
244(1)
Summary
244(1)
11 Tailor Swyfte
245(32)
How tail Works
245(5)
Getting Started
250(17)
Defining the Arguments
250(5)
Parsing Positive and Negative Numeric Arguments
255(1)
Using a Regular Expression to Match an Integer with an Optional Sign
256(4)
Parsing and Validating the Command-Line Arguments
260(2)
Processing the Files
262(1)
Counting the Total Lines and Bytes in a File
262(2)
Finding the Starting Line to Print
264(1)
Finding the Starting Byte to Print
265(1)
Testing the Program with Large Input Files
266(1)
Solution
267(8)
Counting All the Lines and Bytes in a File
267(1)
Finding the Start Index
268(1)
Printing the Lines
269(2)
Printing the Bytes
271(2)
Benchmarking the Solution
273(2)
Going Further
275(1)
Summary
275(2)
12 Fortunate Son
277(26)
How fortune Works
278(3)
Getting Started
281(15)
Defining the Arguments
282(6)
Finding the Input Sources
288(3)
Reading the Fortune Files
291(2)
Randomly Selecting a Fortune
293(2)
Printing Records Matching a Pattern
295(1)
Solution
296(5)
Going Further
301(1)
Summary
301(2)
13 Rascalry
303(26)
How cal Works
303(3)
Getting Started
306(15)
Defining and Validating the Arguments
307(11)
Writing the Program
318(3)
Solution
321(5)
Going Further
326(1)
Summary
326(3)
14 Elless Island
329(32)
How Is Works
330(2)
Getting Started
332(17)
Defining the Arguments
333(3)
Finding the Files
336(5)
Formatting the Long Listing
341(2)
Displaying Octal Permissions
343(3)
Testing the Long Format
346(3)
Solution
349(6)
Notes from the Testing Underground
355(3)
Going Further
358(1)
Summary
359(2)
Epilogue 361(2)
Index 363
Ken Youens-Clark is the author of Tiny Python Projects (Manning, 2020) and Mastering Python for Bioinformatics (OâReilly, 2021). Ken is a senior-level developer with 25 years of experience writing and supporting code written in many languages who has spent several years teaching beginning coding at the university level, and is deeply committed to creating useful teaching resources for people who wish to learn coding.