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
whereclause -
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 ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access