| Crates.io | conversions_rs |
| lib.rs | conversions_rs |
| version | 1.2.1 |
| created_at | 2025-10-26 11:56:40.933909+00 |
| updated_at | 2025-10-26 15:30:56.718759+00 |
| description | A comprehensive unit conversion library, CLI tool, and WebAssembly module with full SI (International System of Units) support |
| homepage | https://github.com/RK1PF/conversions_rs |
| repository | https://github.com/RK1PF/conversions_rs |
| max_upload_size | |
| id | 1901315 |
| size | 354,148 |
A comprehensive command-line unit conversion tool and Rust library with full SI (International System of Units) support.
Install the binary directly from crates.io:
cargo install conversions_rs
Download the latest binary for your platform from the releases page.
Clone the repository and build from source:
git clone https://github.com/RK1PF/conversions_rs.git
cd conversions_rs
cargo build --release
# The binary will be in target/release/conversions_rs
Add this to your Cargo.toml:
[dependencies]
conversions_rs = "1.2.0"
Install from npm for use in web browsers or Node.js:
npm install conversions_rs
Or download WASM packages directly from the releases page:
conversions_rs-wasm-web.tar.gz - For web browsersconversions_rs-wasm-nodejs.tar.gz - For Node.js applicationsconversions_rs-wasm-bundler.tar.gz - For bundlers (webpack, rollup, etc.)โจ Multi-Platform Support: Command-line tool, Rust library, and WebAssembly module for web browsers
You can use the app directly from the command line for quick conversions:
# SI Base Units
conversions_rs length 100 ft m # 100 feet to meters
conversions_rs weight 10 kg lb # 10 kilograms to pounds
conversions_rs temperature 32 F C # 32ยฐF to Celsius
conversions_rs time 3600 s min # 3600 seconds to minutes
conversions_rs current 1500 mA A # 1500 milliamperes to amperes
conversions_rs amount 0.5 mol mmol # 0.5 moles to millimoles
conversions_rs luminosity 2.5 cd mcd # 2.5 candela to millicandela
# SI Derived Units
conversions_rs volume 1 gal l # 1 gallon to liters
conversions_rs area 10000 "mยฒ" ha # 10000 square meters to hectares
Get help:
conversions_rs --help # General help
conversions_rs length --help # Help for length conversions
conversions_rs time --help # Help for time conversions
conversions_rs current --help # Help for current conversions
# ... and all other conversion types
Run without arguments for the interactive menu:
cargo run
The app provides an interactive menu where you can:
Command-Line Mode:
$ conversions_rs length 100 ft m
100 ft = 30.479999 m
$ conversions_rs temperature 32 F C
32ยฐF = 0.00ยฐC
$ conversions_rs weight 5 kg lb
5 kg = 11.023100 lb
$ conversions_rs volume 1 gal l
1 gal = 3.785410 l
Interactive Mode:
๐ Unit Conversion App
======================
Choose conversion type:
1. ๐ Length
2. โ๏ธ Weight/Mass
3. ๐ก๏ธ Temperature
4. ๐งช Volume
5. ๐ช Exit
Enter your choice (1-5): 1
๐ Length Conversion
Supported units: m, km, cm, mm, ft, in, yd, mi
Enter the value to convert: 100
From unit: ft
To unit: m
โ
100 ft = 30.480000 m
You can use the conversion functions directly in your Rust code in multiple ways:
use conversions_rs::*;
// Length conversion
let meters = convert_length(100.0, "ft", "m").unwrap();
println!("{} meters", meters); // 30.48 meters
// Temperature conversion
let fahrenheit = convert_temperature(0.0, "C", "F").unwrap();
println!("{}ยฐF", fahrenheit); // 32ยฐF
// Weight conversion
let pounds = convert_weight(1.0, "kg", "lb").unwrap();
println!("{} lbs", pounds); // 2.20462 lbs
// Volume conversion
let milliliters = convert_volume(1.0, "gal", "ml").unwrap();
println!("{} ml", milliliters); // 3785.41 ml
use conversions_rs::conversions::length::*;
// Using the modular API - more organized and discoverable
let feet = meters::to_feet(10.0); // 32.8084 feet
let inches = feet::to_inches(5.0); // 60.0 inches
let cm = inches::to_centimeters(12.0); // 30.48 cm
let km = miles::to_kilometers(5.0); // 8.0467 km
// Chain conversions easily
let result = meters::to_feet(kilometers::to_meters(1.0)); // 1 km to feet
use conversions_rs::*;
// Traditional function names still work
let feet = meters_to_feet(10.0);
let kg = pounds_to_kilograms(22.0);
let fahrenheit = celsius_to_fahrenheit(25.0);
let ml = liters_to_milliliters(2.5);
The library can be compiled to WebAssembly for use in web browsers and JavaScript environments.
Option 1: Install from npm (Recommended)
npm install conversions_rs
Option 2: Download from GitHub Releases Download the appropriate WASM package from the releases page:
conversions_rs-wasm-web.tar.gz - For web browsersconversions_rs-wasm-nodejs.tar.gz - For Node.js applicationsconversions_rs-wasm-bundler.tar.gz - For bundlers (webpack, rollup, etc.)Option 3: Build from source
First, install wasm-pack:
cargo install wasm-pack
Use the provided build scripts to compile for different WASM targets:
Windows:
./build-wasm.bat
Unix/Linux/macOS:
./build-wasm.sh
This will generate WASM packages in the pkg/ directory for different targets:
pkg/web/ - For direct browser usagepkg/nodejs/ - For Node.js applicationspkg/bundler/ - For webpack, rollup, etc.Using npm package:
import init, {
convert_length_wasm,
convert_weight_wasm,
convert_temperature_wasm,
convert_volume_wasm,
convert_time_wasm,
convert_area_wasm,
get_supported_units
} from 'conversions_rs';
// Initialize the WASM module
await init();
Using local build:
import init, {
convert_length_wasm,
convert_weight_wasm,
convert_temperature_wasm,
convert_volume_wasm,
convert_time_wasm,
convert_area_wasm,
get_supported_units
} from './pkg/web/conversions_rs.js';
// Initialize the WASM module
await init();
Example usage:
// Perform conversions
const lengthResult = convert_length_wasm(100, "ft", "m");
if (lengthResult.success) {
console.log(`100 feet = ${lengthResult.value} meters`);
} else {
console.error("Conversion failed:", lengthResult.error);
}
// Temperature conversion
const tempResult = convert_temperature_wasm(25, "C", "F");
console.log(`25ยฐC = ${tempResult.value}ยฐF`); // 25ยฐC = 77ยฐF
// Get supported units for a conversion type
const lengthUnits = get_supported_units("length");
console.log("Length units:", lengthUnits);
// Output: ["m", "km", "cm", "mm", "ft", "in", "yd", "mi", ...]
All WASM conversion functions return a ConversionResult object:
interface ConversionResult {
success: boolean; // Whether the conversion succeeded
value: number; // The converted value (0 if failed)
error?: string; // Error message if conversion failed
}
A complete HTML demo is provided in demo.html that showcases all WASM functionality.
Open it in a web browser (must be served over HTTP/HTTPS) to try the conversions interactively.
React/Next.js:
import { useEffect, useState } from 'react';
import init, { convert_length_wasm } from './pkg/web/conversions_rs.js';
function Converter() {
const [wasmReady, setWasmReady] = useState(false);
useEffect(() => {
init().then(() => setWasmReady(true));
}, []);
const handleConvert = () => {
if (!wasmReady) return;
const result = convert_length_wasm(100, "ft", "m");
if (result.success) {
console.log("Converted:", result.value);
}
};
return wasmReady ? (
<button onClick={handleConvert}>Convert 100ft to meters</button>
) : (
<div>Loading WASM...</div>
);
}
Node.js:
const { convert_length_wasm } = require('./pkg/nodejs/conversions_rs.js');
const result = convert_length_wasm(100, "ft", "m");
console.log(`100 feet = ${result.value} meters`);
The WASM module supports all modern browsers with WebAssembly support:
For older browsers, consider using a WebAssembly polyfill.
m, meter, meters - Meterskm, kilometer, kilometers - Kilometerscm, centimeter, centimeters - Centimetersmm, millimeter, millimeters - Millimetersft, foot, feet - Feetin, inch, inches - Inchesyd, yard, yards - Yardsmi, mile, miles - Mileskg, kilogram, kilograms - Kilogramsg, gram, grams - Gramslb, lbs, pound, pounds - Poundsoz, ounce, ounces - Ouncest, ton, tons - Metric Tonsst, stone, stones - StonesC, celsius - CelsiusF, fahrenheit - FahrenheitK, kelvin - Kelvinl, liter, liters, litre, litres - Litersml, milliliter, milliliters - Millilitersgal, gallon, gal_us - US Gallonsgal_uk, gallon_uk - UK Gallonsfl_oz, fl_oz_us, fluid_ounce - US Fluid Ouncesfl_oz_uk, fluid_ounce_uk - UK Fluid Ouncescup, cups, cup_us - US Cupspt, pint, pints, pt_us - US Pintsqt, quart, quarts, qt_us - US Quarts# Build the project
cargo build
# Build for release (optimized)
cargo build --release
# Run tests
cargo test
# Check code without building
cargo check
To use the app from anywhere on your system:
# Build release version
cargo build --release
# The executable will be at: target/release/conversions_rs.exe (Windows) or target/release/conversions_rs (Unix)
# On Windows, you can add the target/release directory to your PATH
# Or copy conversions_rs.exe to a directory that's already in your PATH
# On Unix/Linux/Mac:
# sudo cp target/release/conversions_rs /usr/local/bin/
You can use Conversions RS as a library in your Rust projects:
use conversions_rs::conversions::length;
fn main() {
let meters = length::feet_to_meters(100.0);
println!("100 feet = {} meters", meters);
let feet = length::meters_to_feet(30.48);
println!("30.48 meters = {} feet", feet);
}
We welcome contributions! Please see CONTRIBUTING.md for guidelines on how to contribute to this project.
git checkout -b feature/amazing-feature)cargo test)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is dual-licensed under either:
at your option.
See CHANGELOG.md for a detailed history of changes to this project.
Made with โค๏ธ by Raihau GRAFFE
Then you can use it directly:
converions length 100 ft m
converions temperature 25 C F
The project includes comprehensive unit tests covering:
Run tests with:
cargo test
src/
โโโ main.rs # CLI application entry point
โโโ lib.rs # Library entry point and tests
โโโ conversions/
โโโ mod.rs # Module declarations
โโโ length.rs # Length conversion functions
โโโ weight.rs # Weight/mass conversion functions
โโโ temperature.rs # Temperature conversion functions
โโโ volume.rs # Volume conversion functions
This project is open source and available under the MIT License.
clap - Command-line argument parsing for non-interactive mode