length

Crates.iolength
lib.rslength
version0.2.3
sourcesrc
created_at2019-10-04 13:18:12.704782
updated_at2024-11-05 21:20:18.429158
descriptionA library to handle length/distances easyly. It can parse a string with several units (m, km, mi, ft, ...) into the Length-struct and converting into other units.
homepagehttps://github.com/ringostarr80/rust-length
repositoryhttps://github.com/ringostarr80/rust-length
max_upload_size
id169863
size71,984
Ringo Leese (ringostarr80)

documentation

README

License: CC0 Crates.io Documentation Rust codecov

Purpose

This rust library is intended to do some processing of length values.
It can parse strings with different units (m, km, mi, ft, ...) and converting them into other units.

Usage

To use length, first add this to your Cargo.toml:

[dependencies]
length = "0.2"

Next, add this to your crate:

extern crate length;

use length::{Length, Unit, MetricUnit::*};

fn main() {
    let five_meter = Length::new_string("5m").unwrap();
    assert_eq!("5m", five_meter.to_original_string());
    assert_eq!(5.0, five_meter.value);
    assert_eq!(Unit::Metric(Meter), five_meter.unit);

    let fivehundred_centimeter = five_meter.to(Unit::Metric(Centimeter));
    assert_eq!(500.0, fivehundred_centimer.value);
    assert_eq!(Unit::Metric(Centimeter), fivehundred_centimer.unit);

    // ...
}

Documentation

For the latest documentation and examples, please go to https://docs.rs/length.

Miscellaneous

If you have suggestions or found an error, feel free to open an issue or create a pull request on github.

Commit count: 61

cargo fmt