Crates.io | kissunits |
lib.rs | kissunits |
version | 2.0.0 |
source | src |
created_at | 2020-03-25 18:06:03.153447 |
updated_at | 2020-10-10 18:33:43.728586 |
description | Different units (like distances or coordinates), keeping it small and simple |
homepage | |
repository | https://github.com/dominicparga/kissunits |
max_upload_size | |
id | 222731 |
size | 49,966 |
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.
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
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.