smart-unit-converter-0.1.0 is not a library.
๐ง Smart Unit Converter
A context-aware, highly intuitive command-line unit converter written in Rust. It doesn't just calculate; it understands what you mean. Type naturally, use math expressions, and let the smart engine do the rest!
โจ Features
- ๐ง Context-Aware Parsing: No strict syntax required! It extracts the data it needs from your sentence.
- Example:
how many meters are in 5 kilometers
- Example:
- ๐งฎ Built-in Math Engine: Calculate and convert at the same time using the
evalexprengine.- Example:
distance 5+3 km morspeed 100/2 mph kmh
- Example:
- ๐ Auto-Conversion: Omit the target unit to see conversions to all other units in the category.
- Example:
5 kmconverts to meters, cm, and mm simultaneously.
- Example:
- ๐ค Smart Error Suggestions: Made a typo? The fuzzy matcher will suggest the correct unit.
- Example:
distance 5 kilo mโInvalid unit: 'kilo'. Did you mean 'kilometer'?
- Example:
- ๐ Smart Number Formatting: Automatically adjusts decimal precision for tiny numbers (e.g.,
0.00001 km) and large numbers. - โณ Persistent History: Use Up/Down arrows to navigate command history (powered by
rustyline). History survives app restarts! - โก Dual Mode: Use it interactively (REPL) or directly from the command line (CLI) via
clap.
๐ Supported Categories & Units
| Category | Units Supported |
|---|---|
| Speed | kmh, km/h, ms, m/s, mph |
| Temp | c, celsius, k, kelvin, f, fahrenheit |
| Distance | mm, cm, m, km (+ long names) |
| Mass | mg, g, kg (+ long names) |
| Volume | ml, l, gal (+ long names) |
| Time | s, min, h (+ long names) |
| Area | sqm, m2, sqkm, km2, acre |
| Storage | b, kb, mb, gb (+ long names) |
๐ Getting Started
Prerequisites
You need to have Rust and Cargo installed on your system. If you don't, install them via rustup.
Installation
-
Clone the repository:
-
Build the project (Release mode for best performance):
-
Run the executable:
๐ป Usage
Interactive Mode (REPL)
Run the app and start typing naturally:
===
|
> speed
> how
> convert
> distance
> 50
> 1
CLI Mode (One-liner)
You can also use it directly from the terminal without entering the REPL:
๐ ๏ธ Architecture & Tech Stack
This project isn't just a script; it's built with software engineering best practices in mind:
- Traits for DRY Code: The
LinearUnittrait abstracts the conversion logic (to_base&convert_from_base). Adding a new category requires adding just one file and implementing the traitโno need to touch the core logic. - Robust Error Handling: Uses the
thiserrorcrate to define custom, user-friendlyAppErrortypes instead of panicking or usingunwrap(). - Regex Entity Extraction: The parser uses
regexto decouple numbers from units (e.g., parsing5kminto5andkm), allowing flexible sentence structures. - Math Evaluation: Integrates
evalexprsafely, handling both Integer and Float returns seamlessly. - Linting: Passes
cargo clippywith zero warnings.
Crates Used
clap- CLI argument parsingrustyline- Readline implementation for history/navigationregex- Context-aware string parsingevalexpr- Math expression evaluationthiserror- Error handling derivationcolored- Terminal color output
๐ค Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
- Fork the project
- Create your feature branch (
git checkout -b feature/NewCategory) - Commit your changes (
git commit -m 'Add NewCategory') - Push to the branch (
git push origin feature/NewCategory) - Open a Pull Request
๐ License
This project is Apache 2.0 licensed.