Chapter 11. Tailor Swyfte
From the embryonic whale to the monkey with no tail
They Might Be Giants, “Mammal” (1992)
The challenge in this chapter will be to write a version of tail
, which is the converse of head
from Chapter 4.
The program will show you the last bytes or lines of one or more files or STDIN
, usually defaulting to the last 10 lines.
Again the program will have to deal with bad input and will possibly mangle Unicode characters.
The challenge program will read only regular files, so we won’t bother with STDIN
.
In this chapter, you will learn how to do the following:
-
Initialize a static, global, computed value
-
Seek to a line or byte position in a filehandle
-
Indicate multiple trait bounds on a type using the
where
clause -
Build a release binary with Cargo
-
Benchmark programs to compare runtime performance
How tail Works
To demonstrate how the challenge program should work, I’ll first show you a portion of the manual page for the BSD tail
.
Note that the challenge program will only implement some of these features:
TAIL(1) BSD General Commands Manual TAIL(1) NAME tail -- display the last part of a file SYNOPSIS tail [-F | -f | -r] [-q] [-b number | -c number | -n number] [file ...] DESCRIPTION The tail utility displays the contents of file or, by default, its stan- dard input, to the standard output. The display begins at a byte, line or 512-byte block location in the input. Numbers having a leading plus ('+') sign are relative to the beginning of the ...
Get Command-Line Rust now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.