Lab 5: Gutensearch
Due: 2024-10-14 at 23:59
In this lab, you’re going to build a simple command-line search interface to Project Gutenberg. You’re going to read an index from a file and create objects representing entry.
In this lab, you’ll learn
- how to create a generic
Result<T>
type alias which you can use to return multiple types of errors from a function; - how to use
struct
s andenum
s to structure related data; - how to implement methods for
struct
s andenums
; and - how to implement a trait.
In the first part of this lab (which contains a lot of text to read but very little actual coding), you’ll learn a generic method for handling errors in functions which we’ll use for the rest of the semester.
In the subsequent parts, you’re going to implement an interactive search interface. When you run your completed program, you should see
$ cargo run --quiet
Welcome to Gutensearch! The index contains 71329 entries.
Example queries to search titles, authors, or both:
> title: two cities
> author: wodehouse
> shelley
Enter a search query (Ctrl-D to exit)
>
and then you’ll be able to enter search queries and get back nicely formatted entries. E.g., here’s one of the entries for the query: title: two cities
:
Author: Dickens, Charles
Title: A Tale of Two Cities
URL: https://www.gutenberg.org/ebooks/98
Resources:
- text: https://www.gutenberg.org/ebooks/98.html.images
- text: https://www.gutenberg.org/files/98/98-h/98-h.htm
- text: https://www.gutenberg.org/files/98/98-h.zip
- epub: https://www.gutenberg.org/ebooks/98.epub3.images
- epub: https://www.gutenberg.org/ebooks/98.epub.images
- epub: https://www.gutenberg.org/ebooks/98.epub.noimages
- text: https://www.gutenberg.org/files/98/98-0.txt
- text: https://www.gutenberg.org/files/98/98-0.zip
Preliminaries
First, find a partner. You’re allowed to work by yourself, but I highly recommend working with a partner. Click on the assignment link. One partner should create a new team. The team name cannot be the same name used for a previous lab. The second partner should click the link and choose the appropriate team. (Please don’t choose the wrong team, there’s a maximum of two people and if you join the wrong one, you’ll prevent the correct person from joining.) You cannot choose a team name you’ve used previously.
Once you have accepted the assignment and created/joined a team, you can clone the repository and begin working.
Be sure to ask any questions on Ed.
Compiler warnings and errors
Make sure your code compiles and passes clippy
without errors or warnings.
That is, running
$ cargo clean
$ cargo build
$ cargo clippy
should build your program without errors or warnings.
Formatting
Your code must be formatted by running cargo fmt
.