pub struct FileSize {
pub pb: u16,
pub tb: u16,
pub gb: u16,
pub mb: u16,
pub kb: u16,
pub b: u16,
}Expand description
The size of a file, consisting of counts for data units.
Fields§
§pb: u16Pebibytes (250 bytes) component of the file size
tb: u16Tebibytes (240 bytes) component of the file size
gb: u16Gibibytes (230 bytes) component of the file size
mb: u16Mebibytes (220 bytes) component of the file size
kb: u16Kibibytes (210 bytes) component of the file size
b: u16Bytes component of the file size
Implementations§
Source§impl FileSize
impl FileSize
Sourcepub fn from_total_bytes(total_bytes: u64) -> Self
pub fn from_total_bytes(total_bytes: u64) -> Self
Returns a new FileSize with representing given number of bytes
This produces a FileSize with optimal values for each count
field. In other words, the largest possible units are filled
first, rather than just setting the bytes field to the input.
§Arguments
total_bytes- The number of bytes the newFileSizeshould represent
§Examples
use zeus_fm::zeuslib::utils::fs::FileSize;
const b: u64 = 1048726;
let fs = FileSize::from_total_bytes(b);
assert_eq!(fs.pb, 0);
assert_eq!(fs.tb, 0);
assert_eq!(fs.gb, 0);
assert_eq!(fs.mb, 1);
assert_eq!(fs.kb, 0);
assert_eq!(fs.b, 150);Sourcepub fn get_total_bytes(&self) -> u64
pub fn get_total_bytes(&self) -> u64
Get the total number of bytes in this FileSize
§Examples
use zeus_fm::zeuslib::utils::fs::FileSize;
const b: u64 = 1048576;
let fsize = FileSize::from_total_bytes(b); // Create a `FileSize`
let total_bytes = fsize.get_total_bytes(); // Get the total number of bytes
assert_eq!(total_bytes, b);Sourcepub fn get_fractional_pb(&self) -> f64
pub fn get_fractional_pb(&self) -> f64
Get the total number of Pebibytes (250 bytes) this FileSize represents as a
floating-point number.
Sourcepub fn get_fractional_tb(&self) -> f64
pub fn get_fractional_tb(&self) -> f64
Get the total number of Tebibytes (240 bytes) this FileSize represents as a
floating-point number.
Sourcepub fn get_fractional_gb(&self) -> f64
pub fn get_fractional_gb(&self) -> f64
Get the total number of Gibibytes (230 bytes) this FileSize represents as a
floating-point number.
Sourcepub fn get_fractional_mb(&self) -> f64
pub fn get_fractional_mb(&self) -> f64
Get the total number of Mebibytes (220 bytes) this FileSize represents as a
floating-point number.
Sourcepub fn get_fractional_kb(&self) -> f64
pub fn get_fractional_kb(&self) -> f64
Get the total number of Kibibytes (210 bytes) this FileSize represents as a
floating-point number.