4个版本

0.1.16 2024年1月27日
0.1.15 2024年1月27日
0.1.13 2022年12月16日
0.1.11-alpha.52022年2月15日
0.1.11-alpha.3 2022年2月14日

#122算法


2 crates 中使用

MIT 许可协议

250KB
3.5K SLoC

Rust单位转换

Build GitHub license GitHub Releases GitHub Issues

该项目的主要目标是生成各种测量单位(如下所示)的转换函数。代码和单元测试由UnitCodeGenerator工具自动生成。因此,任何更改都需要在定义文件中进行。

通过 crates.io 提供

单位转换也适用于

C#
Dart
F#
Go
Java
Python
Swift
TypeScript

示例

使用示例

use unit_conversions::*;

fn main() {
    let radians: f64 = angle::degrees::to_radians(800.0);
    println!("{}", radians);
}

每个测量单位都包括将每个单位转换为其他单位的功能,例如,将每个温度单位转换为其他温度单位。

角度

* Degrees (deg)
* Gradians (grad)
* Milliradians (mrad)
* Minute Of Arc (arcmin)
* Radians (rad)
* Seconds Of Arc (arcseconds)

面积

* Acres (acre)
* Hectares (hectare)
* Square Feet (feet2)
* Square Inches (inch2)
* Square Kilometres (km2)
* Square Metres (m2)
* Square Miles (mile2)
* Square Yards (yard2)

数据存储

* Bits (b)
* Gigabits (Gb)
* Gigabytes (GB)
* Kibibits (kibibit)
* Kilobits (k)
* Kilobytes (KB)
* Mebibits (mebibit)
* Megabits (Mb)
* Megabytes (MB)
* Terabits (Tb)
* Terabytes (TB)

数据传输速率

* Bits Per Second (bps)
* GigaBits Per Second (Gbps)
* GigaBytes Per Second (GBps)
* Kibibits Per Second (Kibitps)
* KiloBits Per Second (kbps)
* KiloBytes Per Second (kBps)
* Mebibits Per Second (Mibit)
* MegaBits Per Second (Mbps)
* MegaBytes Per Second (MBps)
* TeraBits Per Second (Tbps)
* TeraBytes Per Second (TBps)

能量

* Btu (btu)
* Calories (cal)
* Electronvolts (eV)
* Foot Pounds (ftlb)
* Joules (J)
* Kilocalories (kCal)
* Kilojoules (kJ)
* Kilowatt Hours (kWh)
* US Therms (ustherm)
* Watt Hours (Wh)

* Dynes (dyn)
* Kilogram-force (kp)
* Newtons (N)
* Poundals (pdl)

频率

* Gigahertz (GHz)
* Hertz (Hz)
* Kilohertz (kHz)
* Megahertz (MHz)

燃油经济性

* Kilometre Per Litre (kml)
* Litres Per 100 Kilometres (l100km)
* Miles Per Gallon (mpg)
* US Miles Per Gallon (usmpg)

长度

* Centimetres (cm)
* Feet (ft)
* Inches (inch)
* Kilometres (km)
* Metres (m)
* Miles (mile)
* Millimetres (mm)
* Nautical Miles (NM)
* Yards (yard)

光能

* LumenHour (lmh)
* LumenMinute (lmmin)
* LumenSecond (lms)
* Talbot (T)

磁动势

* Ampere-turns (AT)
* Gilberts (Gi)

质量

* Carats (ct)
* Grams (g)
* Kilograms (kg)
* Milligrams (mg)
* Ounces (oz)
* Pounds (lb)
* Stones (stone)
* Tonnes (tonne)

功率

* Mechanical Horse Power (hp)
* Metric Horse Power (ps)

压力

* Atmospheres (atm)
* Bars (b)
* Pascals (Pa)
* Psi (psi)
* Torrs (Torr)

速度

* Feet Per Second (fps)
* Kilometres Per Hour (kph)
* Knots (knot)
* Metres Per Second (mps)
* Miles Per Hour (mph)

温度

* Celsius (C)
* Fahrenheit (F)
* Kelvin (K)
* Rankine (R)
* Réaumur (r)

时间

* Centuries (century)
* Days (day)
* Decades (decade)
* Hours (hour)
* Microseconds (microsecond)
* Milliseconds (millisecond)
* Minutes (minute)
* Months (month)
* Nanoseconds (nanosecond)
* Seconds (second)
* Weeks (week)
* Years (year)

体积

* Cubic Feet (feet3)
* Cubic Inches (inch3)
* Cubic Metres (m3)
* Fluid Ounces (floz)
* Gallons (gal)
* Kilolitres (kl)
* Litres (l)
* Millilitres (ml)
* Oil Barrels (oilbarrel)
* Pints (pt)
* Quarts (qt)
* Tablespoons (tbsp)
* Teaspoons (tsp)
* US Cups (uscup)
* US Fluid Ounces (usfloz)
* US Gallons (usgal)
* US Pints (uspt)
* US Quarts (usqt)
* US Tablespoons (ustbsp)
* US Teaspoons (ustsp)

应用程序

"我的单位转换"应用程序。(适用于Android、iOS和Windows)使用此库的C#(PutridParrot.Units)版本,可以从以下商店/位置获取。

Get it on Google Play Download on the Apple Store Available on Fire Available on Windows

应用程序的Mac版本使用此Swift包,可以从以下位置获取

Download on the Apple Store

无运行时依赖