In-Memory Key-Value Store with REPL
Build a small interactive database in Rust that you use from the terminal: type set name Ana, get name, delete name, list or clear, and it answers right away, like a tiny Redis. Data is kept in a HashMap in memory, and you can save it to a file and load it again next time. It's a gentle first Rust project: you'll learn reading input in a loop (a REPL), splitting text into commands, matching commands with enums and match, using HashMap, ownership and borrowing in practice, handling errors with Result, and reading and writing files.
- Estimate
- ~6.5h
- Steps
- 5
- Completed by
- 0
- Proposed by
- codeseed.app
Standard Library
Project roadmap
- 01
Build the input loop
~1hCreate a project with cargo new kvstore. Write a loop that prints a > prompt, reads a line from standard input with read_line, trims it, and stops on exit, quit or end of input (Ctrl+D). Print unknown input back with a message. Done when: the program keeps reading commands until you type exit.
- 02
Parse commands
~1.5hDefine a Command enum (Set { key, value }, Get(key), Delete(key), List, Clear, Save(path), Load(path), Help) and a parse function returning Result<Command, String>. Values can contain spaces (set greeting hello world). Return a clear error for missing arguments or unknown commands. Write unit tests for the parser. Done when: the parser tests pass for valid and invalid commands.
- 03
Implement the store
~1.5hCreate a Store struct wrapping HashMap<String, String> with set, get, delete, list and clear methods. Run each parsed command with a match: set prints OK, get prints the value or (nil), delete says whether the key existed, list prints keys sorted alphabetically with their values, and clear asks for confirmation. Done when: every command works in the REPL.
- 04
Save and load a file
~1.5hAdd save FILE and load FILE, and load data.txt automatically at startup when it exists. Use a simple format such as one key<TAB>value per line, and handle tabs or new lines inside values by escaping them. Report file errors (missing file, no permission) with a message instead of crashing, using the ? operator inside functions that return Result. Done when: data saved in one run is loaded in the next.
- 05
Test it
~1hWrite tests for the Store methods and for saving and loading (write to a temporary file, load it into a new store, and compare), including values with spaces and tabs. Run cargo clippy and fix its suggestions. Done when: cargo test passes, and clippy has no warnings.
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack