Function lib::convert_units

source ·
pub fn convert_units(value: u64, from: &str, to: &str) -> u64
Expand description

Converts a value from one unit to another.

§Arguments

  • value - The numerical value to be converted.
  • from - The unit of the input value (e.g., “bit”, “byte”, “kb”).
  • to - The unit to convert the value to (e.g., “bit”, “byte”, “kb”). Units: bit,byte,kb,mb,gb,tb,pb,eb
 use data_units::convert_units;
 let result = convert_units(8, "bit", "byte"); // 1

§Returns

The converted value in the target unit.

§Example

use data_units::convert_units;
let result = convert_units(8, "bit", "byte");
assert_eq!(result, 1);