#distance #meters #si-units #velocity #haversine

kissunits

Different units (like distances or coordinates), keeping it small and simple

7 releases (stable)

2.0.0 Oct 10, 2020
1.1.0 May 18, 2020
1.0.3 Mar 27, 2020
1.0.2 Mar 26, 2020
0.0.0 Mar 25, 2020

#52 in Math

Download history 82/week @ 2020-06-30 59/week @ 2020-07-07 81/week @ 2020-07-14 13/week @ 2020-07-21 1/week @ 2020-07-28 7/week @ 2020-08-04 21/week @ 2020-08-11 10/week @ 2020-08-18 11/week @ 2020-08-25 9/week @ 2020-09-01 21/week @ 2020-09-08 3/week @ 2020-09-15 4/week @ 2020-09-22 3/week @ 2020-09-29 34/week @ 2020-10-06 5/week @ 2020-10-13

69 downloads per month
Used in osmgraphing

Apache-2.0

24KB
665 lines

Units kept small and simple

Build Status nightly

Tag Crates.io Docs

Changelog Last commit

License

Welcome! :) Goal of this repo is to provide a simple and explicit implementation of units, without specialties or complex/implicit behaviour.

An example, including an example for forbidden implicit behaviour, is the following code-snippet:

use kissunits::{
    distance::{Kilometers, Meters},
    time::{Hours, Seconds},
};

fn main() {
    // use the struct directly
    let m = Meters(72_000.0);
    let h = Hours(2.0);

    // compile-error since resulting unit is not clear
    println!("{}", m / h); // ERROR

    // prints 36 km/h
    let km = Kilometers::from(m);
    println!("{} / {} = {}", km, h, km / h);

    // prints 10 m/s
    let s = Seconds::from(h);
    println!("{} / {} = {}", m, s, m / s);
}

One could argue, that the resulting type could be specified explicitly, like

let mps: MetersPerSecond = m / h;

but this would lead to implicit rounding errors.

Setup and usage

Rust has a build-tool called cargo, which can be used to run everything except scripts in scripts/.

# Just executing some easy cargo-build-commands
./scripts/build.sh
# Run the example
cargo run --example basic

Credits

The project started in the early 2020. This section honors the workers and helpers of this project, sorted by their last names.

Dominic Parga Cacheiro
has written these units.

No runtime deps