Skip to content

da578/library-management-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Library Management System

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.

Features

  • 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

Technology Stack

  • Language: Rust 1.91.1+
  • Dependencies:
    • compact_str - Memory-efficient string handling
    • chrono - Date and time operations
    • regex - Email validation
  • Collections Used:
    • Vec<T> - For sequential storage of books and users
    • String/CompactString - For text data management
    • HashMap<K, V> - For O(1) lookups and relationship mapping
    • Rc<RefCell<T>> - For shared ownership and interior mutability

Installation & Setup

Prerequisites

  • Rust installed (v1.91.1+)

Steps

  1. Clone the repository:
git clone https://github.com/yourusername/library-management-system.git
cd library-management-system
  1. Install dependencies:
cargo build
  1. Run the application:
cargo run

Usage

The 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

Example Workflow

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)

Project Structure

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

Key Learning Points

  • 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

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A simple Library Management System built with Rust demonstrating practical usage of vectors, strings, and hash maps from Chapter 8 of The Rust Programming Language book. Features book/user management, borrowing system, and CLI interface.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages