An educational warehouse management program written in Rust showcasing idiomatic Rust usage (e.g. ownership and borrowing, iterators, custom structs) and domain-focused data structures for efficient look-ups and allocations.
Originally developed as a final exercise while following a Rust fundamentals course.
Exercise problem statement
The goal is to design a versatile and efficient warehouse managing system.
The warehouse is composed of rows that contain shelves. Each shelf has mutliple levels, and each level has multiple zones. Each zone can only contain one item.
Inside the warehouse we can keep any kind of item. These items are defined by their id, name, quantity, and quality (see below), and timestamp of when it is stored.
Each item has its own independent quantity, while being treated as a single item, (think of a single pallet or package which can contain a variable quantity of something inside) but we can have multiples of the same kind of item inside the Warehouse.
The quality of an item can be of 3 categories, and each category can have its own special requirements beyond the ones specified above:
- Normal - A normal item does not have any special requirements.
- Oversized - Oversized items occupy several contiguous zones, therefore they cannot be placed over row/shelf/level boundaries.
- Fragile - Fragile items have an expiration date, and a max level above which they cannot be stored.
The program must be capable of allocating and inserting an item where, for a given warehouse state, the following strategies are used:
- Items must be stored in the first available spot, closest to the entrance. (Row 0 is considered the closest row, in which Shelf 0 is considered the closes shelf, etc.)
- Items must be stored in round robin fashion, ignoring spots that may have become empty in the meantime due to item removal until the whole warehouse is iterated over.
The program must also be capable of efficiently performing:
- A search by ID, returning items with that ID, if any.
- A search by name, returning items with that name, if any.
- A search that returns the zone (including row, shelf, and level) of a certain item, by ID. If multiple items with the same ID exist, return all.
- The allocation of a new item.
- The insertion of a new item in a valid spot, considering the strategies above.
- Removal of an item by zone.
- A search for all items in the warehouse at that moment, returning an alphabetically sorted list.
- A search for items whose expiration date is 3 or fewer days away of a given date, chosen by the user.
Click to expand
This project simulates a simplified warehouse layout with fixed dimensions.
The problem requirements state that a warehouse is composed by rows of shelves. Each shelf has multiple levels (height), and each level has a number of zones, the space an item typically occupies. Therefore, it can be represented by the following 4-dimensional structure:
- Rows - Represent lines of shelves
- Shelves - Each shelf has multiple vertical levels
- Levels - Each level has multiple slots ("zones") for items.
- Zones - A slot for one typical item ("oversized" items may occupy more than one zone).
These terms show up frequently in the UI and the code. For example, an item may be allocated in "Row: 1, Shelf: 2, Level: 0, Zone: 4" (coordinates are 0-indexed).
Due to the educational nature of this project, in this implementation the number of rows, shelves, levels, and zones was chosen to be "5", giving the warehouse a total capacity of 5 * 5 * 5 * 5 = 625 storage slots.
This design choice was intentional, but the sizes can be easily changed in their relevant const definitions in warehouse.rs. The logic within is agnostic to this warehouse size, and supports different dimensions.
As per the problem statement, multiple items can have the same ID, therefore the ID is not forced to be unique and cannot uniquely identify one item by design.
- Reasoned choices of data structures: iteration, look-up, and sorting speed were considered.
- Idiomatic abstractions: E.g. a custom
WarehouseCoordsIterator implementation. - Practical Rust ergonomics: E.g.
Resultfor recoverable errors, methodical use of built-in functions for handling Rust structures/iterators. - Modular thinking: Clean separation of UI and warehouse logic.
- A small, basic TUI built with
crosstermthat demonstrates interactive input handling and terminal control (although this was not the focus of the course).
- Create / remove items to simulate a warehouse setting, storing properties like name and quantity.
- Support item variants with additional requirements, such as Oversized and Fragile items.
- Fast and efficient look-ups by 'id' and 'name' via HashMaps.
- Sorted listing by name via BTreeMap.
- Two allocation strategies: first-fit (closest to entrance), and round-robin.
- List items nearing expiration.
Prerequisites: Rust toolchain (rustup, cargo).
# clone
git clone git@github.com:Ric-JT/rust-warehouse.git
cd rust-warehouse
# build and run
cargo build --release
cargo run --releasesrc/main.rs- program entry and clean-up.src/warehouse.rs- domain data structures and logic.src/ui.rs- terminal UI, including menu rendering and input handling.
- Polish TUI for better user experience and more robust input handling.
- Add unit testing for automated validation of indexing and allocation.
E-mail: ricardo.j.trancoso@gmail.com