smart-unit-converter-0.1.1 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:
- 🗣️ Plurals Support: Understands natural language plurals.
- Example:
100 kilometers to meters
- 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 | Supported Units (Abbreviations & Names) |
|---|---|
| Speed | kmh, km/h, ms, m/s, mph |
| Temp | c, celsius, k, kelvin, f, fahrenheit |
| Distance | mm, cm, m, km, millimeter(s), centimeter(s), meter(s), kilometer(s) |
| Mass | mg, g, kg, milligram(s), gram(s), kilogram(s) |
| Volume | ml, l, gal, milliliter(s), liter(s), gallon(s) |
| Time | s, sec(s), min(s), h, hr(s), hour(s) |
| Area | sqm, m2, sqkm, km2, acre(s) |
| Storage | b, kb, mb, gb, byte(s), kilobyte(s), megabyte(s), gigabyte(s) |
🚀 Installation
You can install it directly via Cargo:
Once installed, run it using the command:
💻 Usage
Interactive Mode (REPL)
Run the app and start typing naturally:
===
|
> speed
> how
> convert
> distance
> 1
CLI Mode (One-liner)
You can also use it directly from the terminal without entering the REPL:
🛠️ Architecture & Tech Stack
This project is built with software engineering best practices in mind:
- Traits for DRY Code: The
LinearUnittrait abstracts the conversion logic. Adding a new category requires adding just one file. - Robust Error Handling: Uses the
thiserrorcrate to define custom, user-friendlyAppErrortypes. - Regex Entity Extraction: The parser uses
regexto decouple numbers from units, allowing flexible sentence structures. - Math Evaluation: Integrates
evalexprsafely, handling both Integer and Float returns seamlessly.
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.
📝 License
This project is Apache-2.0 licensed.