A simple yet comprehensive library management system built with Rust, utilizing core collection types (vectors, strings, and hash maps) as covered in Chapter 8 of The Rust Programming Language book.
- Book Management: Add, remove, and search books in the library inventory
- User Management: Register and track library members
- Borrowing System: Handle book borrowing and returning with validation
- Availability Tracking: Real-time tracking of available vs borrowed books
- Search Functionality: Case-insensitive book title search
- Data Persistence: Sample data initialization for demonstration
- Error Handling: Comprehensive error handling with custom error types
- CLI Interface: User-friendly command-line interface with menu system
- Language: Rust 1.91.1+
- Dependencies:
compact_str- Memory-efficient string handlingchrono- Date and time operationsregex- Email validation
- Collections Used:
Vec<T>- For sequential storage of books and usersString/CompactString- For text data managementHashMap<K, V>- For O(1) lookups and relationship mappingRc<RefCell<T>>- For shared ownership and interior mutability
- Rust installed (v1.91.1+)
- Clone the repository:
git clone https://github.com/yourusername/library-management-system.git
cd library-management-system- Install dependencies:
cargo build- Run the application:
cargo runThe system starts with sample data (5 books, 3 users). Use the interactive menu to:
===== Library Management System =====
1. View all available books
2. Search books by title
3. Borrow a book
4. Return a book
5. View user's borrowed books
6. Add new book
7. Register new user
8. Exit
View available books (Option 1) Borrow a book by providing user ID and book ID (Option 3) Check borrowed books for a user (Option 5) Return a book (Option 4) Search for books by title (Option 2)
src/
├── main.rs # Application entry point and CLI interface
├── enums.rs # Custom error enumeration
├── utils.rs # Helper functions (input handling, string manipulation)
├── models/
│ ├── mod.rs # Module aggregation
│ ├── book.rs # Book struct definition
│ ├── user.rs # User struct definition
│ └── library.rs # Core library management logic
Cargo.toml # Project dependencies and metadata
README.md # Project documentation
LICENSE # MIT License
- Vectors (
Vec<T>):- Sequential storage of books and users
- Filtering and iteration operations
- Memory management with owned values
- Strings (
String/CompactString):- Text data handling and manipulation
- Input validation and sanitization
- Efficient string operations
- Hash Maps (
HashMap<K, V>):- O(1) lookup operations for books and users
- Relationship mapping (borrowed books tracking)
- Entry API for efficient updates
- Advanced Concepts:
- Error handling with
Result<T, E> - Ownership and borrowing patterns
- Reference counting (
Rc) and interior mutability (RefCell) - Struct and enum definitions with documentation
- Error handling with
This project is licensed under the MIT License - see the LICENSE file for details.