Library book management using structures

Rust Medium structs

Task «Library book management using structures»

Create a structure `Book` with fields `title` (String), `author` (String), `year` (u32), and `is_available` (bool). Implement functions for adding a book, searching by author, and borrowing a book (changes `is_available` to `false`). Input data: first, a number `n` — the number of operations, then `n` lines, each starting with a command: `"add"` (add a book with parameters `title`, `author`, `year`), `"find"` (find all books by an author and output them in the order they were added), `"borrow"` (borrow a book by `title` — if available, make it unavailable). Output the result for `find` and `borrow` commands.

Input Format

First line: integer n (1 ≤ n ≤ 1000). Then n lines: for the "add" command — add <title> <author> <year>, for "find" — find <author>, for "borrow" — borrow <title>.

Output Format

For each `find` command, output a list of the author's books in the format "title by author (year) - available" or "title by author (year) - borrowed", separated by a comma and a space on a single line. For the `borrow` command, output "success" if the book is borrowed, otherwise "not available".

Examples

Example 1

INPUT
3 Book1 Author1 2000 0 Book2 Author2 2010 1 Book3 Author3 2020 0 print_all
OUTPUT
main.rs