Crates.io | unit_converter_lib |
lib.rs | unit_converter_lib |
version | 0.1.0 |
source | src |
created_at | 2023-11-01 12:42:48.934943 |
updated_at | 2023-11-01 12:42:48.934943 |
description | A library to convert different units |
homepage | |
repository | https://github.com/LukasHuth/UnitConverter |
max_upload_size | |
id | 1020976 |
size | 50,798 |
to import this library use
use unit_converter_lib;
to read the stored value from a unit use .0
convert 5 meters into inches
// import types
use unit_converter_lib::units::length;
// create a variable that stores 5 meters
let meters: length::M = length::M(5.0);
// convert the 5 meters to inches
let converted_result = length::INCH::from(meters);
// load the float value from the unit
let converted_result_as_float = converted_result.0;
get unit by name and save it in a unit container, after that we convert it to meters
use unit_converter_lib::units::length;
// get the unit by it's name
let unit_type: length::UNITS = length::UNITS::by_name("foot");
let value: f64 = 5.0;
// create a unit container with a specified unit and value
let unit_container = length::UnitContainer::new(unit_type, value);
// convert the unit
let converted_result_as_float = length::M::from(unit_container).0;
use unit_converter_lib::units;
let unit = units::<unit type>::<unit>(<value as f64>);
use unit_converter_lib::units;
let unit_type = units::<unit type>::UNITS::<unit>;
let uc = units::<unit type>::UnitContainer::new(unit_type, <value>);
use unit_converter_lib::units;
let uc = units::<unit type>::UnitContainer::<unit>(units::<unit type>::<unit>(<value>));
https://www.isa.org/getmedia/5be3daca-5c44-4d9e-bf1c-a4aa55cfb759/CCST-Conversions-document.pdf