[][src]Struct zeus_fm::zeuslib::utils::fs::filesize::FileSize

pub struct FileSize {
    pub pb: u16,
    pub tb: u16,
    pub gb: u16,
    pub mb: u16,
    pub kb: u16,
    pub b: u16,
}

The size of a file, consisting of counts for data units.

Fields

pb: u16

Pebibytes (250 bytes) component of the file size

tb: u16

Tebibytes (240 bytes) component of the file size

gb: u16

Gibibytes (230 bytes) component of the file size

mb: u16

Mebibytes (220 bytes) component of the file size

kb: u16

Kibibytes (210 bytes) component of the file size

b: u16

Bytes component of the file size

Implementations

impl FileSize[src]

pub fn from_total_bytes(total_bytes: u64) -> Self[src]

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 new FileSize should 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);

pub fn get_total_bytes(&self) -> u64[src]

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);

pub fn get_fractional_pb(&self) -> f64[src]

Get the total number of Pebibytes (250 bytes) this FileSize represents as a floating-point number.

pub fn get_fractional_tb(&self) -> f64[src]

Get the total number of Tebibytes (240 bytes) this FileSize represents as a floating-point number.

pub fn get_fractional_gb(&self) -> f64[src]

Get the total number of Gibibytes (230 bytes) this FileSize represents as a floating-point number.

pub fn get_fractional_mb(&self) -> f64[src]

Get the total number of Mebibytes (220 bytes) this FileSize represents as a floating-point number.

pub fn get_fractional_kb(&self) -> f64[src]

Get the total number of Kibibytes (210 bytes) this FileSize represents as a floating-point number.

Trait Implementations

impl Clone for FileSize[src]

impl Debug for FileSize[src]

impl Display for FileSize[src]

impl Eq for FileSize[src]

impl Ord for FileSize[src]

impl PartialEq<FileSize> for FileSize[src]

impl PartialOrd<FileSize> for FileSize[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.