Unit Converter for Rust Language

Test Current Crates.io Version

§0.0.1 This library allows you to convert a size in bytes into kilobytes, megabytes, gigabytes, and terabytes, as well as perform conversions back to bytes.

§0.0.2 Create a new ByteConverter instance

bytes: The number of bytes to be converted.

use data_storage_units::ByteConverter;
let converter = ByteConverter::new(1024);

§0.0.3 Converts bytes to kilobytes (KB)

A tuple containing the value in kilobytes as f64 and the unit “KB”.

let converter = ByteConverter::new(1024);
let (value, unit) = converter.to_kb();

§0.0.4 Converts bytes to megabytes (MB)

A tuple containing the value in megabytes as f64 and the unit “MB”.

let converter = ByteConverter::new(1073741824);
let (value, unit) = converter.to_mb();

§0.0.5 Converts bytes to gigabytes (GB)

A tuple containing the value in gigabytes as f64 and the unit “GB”.

let converter = ByteConverter::new(1073741824);
/let (value, unit) = converter.to_gb();

§0.0.6 Converts bytes to terabytes (TB)

A tuple containing the value in terabytes as f64 and the unit “TB”.

let converter = ByteConverter::new(1073741824);
let (value, unit) = converter.to_tb();