| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
To start using this library, simply add the following 2 lines to your Cargo.toml:
[dependencies.unitr] git = "https://github.com/uwap/unitr.git"
And add the following to your main.rs / lib.rs:
#![feature(globs)]
extern crate unitr;
use unitr::*;UNITr is a library for rust designed for people having to use units a lot.
Here is a great example of the power of this library:
let distance_walked = 32f64.km();
println!("You walked {} meters!", distance_walked.m().val())As you can see the .km() denotes that the specific value is measured in kilometers.
You can simply use .m() to convert it into meters.
Another example of that:
let distance_walked = 5f64.mm();
println!("You walked {}", distance_walked)Now, this code has the output You walked 5mm. The method .val() used above
will give you the value of this Millimeter type. So distance_walked.val() is 5f64.
When calculating with operators, you may sometimes do mistakes.
For example you have two values of different units and add them together.
let my_centimeters = 100f32;
let my_meters = 0.4f32;
my_centimeters + my_meters // what is the unit now?UNITr makes this way easier.
let my_centimeters = 100f32.cm();
let my_meters = 0.4f32.m();
my_centimeters + my_meters // what is the result? Well, it is 500cm.There are several distance types implemented. Take a look at this list:
As well as distances, UNITr also supports time.
With velocities, UNITr shows its full potential.
let distance = 10f32.m();
let time = 5f32.s();
let velocity = distance / time;
println!("Your speed was {}", velocity.km_h())Dividing distance by time will in fact give you velocities.
There are many, many, many velocity units.
These are made of a distance and a time unit. For example:
Area types can be accessed on two ways. The usual method:
And so on...
Or they can be accessed by multiplying to distances together.
let a = 100.cm();
let b = 80.cm();
let A = a * b;
assert_eq!(A, 8000.cm2())As well as non metric units are still missing, also .a() and .ha() aren't a thing yet.
let a = 1.km();
let b = 2000.m();
let A = a*b;
println!("{}", A) // will print out `4km²`Beside the previous named features we have a lot of things on our todo list.
| Back | FazBrowse Home | New Git URL |