Enum SIUnit

Source
pub enum SIUnit {
    Byte(f64, f64),
    Kilobyte(f64, f64),
    Megabyte(f64, f64),
    Gigabyte(f64, f64),
    Terabyte(f64, f64),
    Petabyte(f64, f64),
    Exabyte(f64, f64),
    Overflow,
}
Available on crate feature size_format only.
Expand description

Represents different units of data size, allowing for conversion between human-readable representations and precise byte values.

This enum supports addition and subtraction operations. However, multiplication and division operations are only supported when working with f64 values.

Variants§

§

Byte(f64, f64)

§

Kilobyte(f64, f64)

§

Megabyte(f64, f64)

§

Gigabyte(f64, f64)

§

Terabyte(f64, f64)

§

Petabyte(f64, f64)

§

Exabyte(f64, f64)

§

Overflow

Implementations§

Source§

impl SIUnit

Source

pub fn new(value: f64, unit_type: SISize) -> SIUnit

Creates a new instance of SIUnit based on the provided value and unit type.

This function is part of the SIUnit enum and supports units such as Byte, Kilobyte, Megabyte, Gigabyte, Terabyte, Petabyte, Exabyte, and Overflow. The conversion is based on the International System of Units (SI) standard for decimal prefixes.

§Arguments
  • value - A positive f64 representing the numeric value of the size.
  • unit_type - An SISize enum specifying the unit type.
§Returns
  • An SIUnit enum representing the converted size.
§Example
use get_chunk::data_size_format::si::{SISize, SIUnit};
use get_chunk::iterator::FileIter;
use get_chunk::ChunkSize;

fn main() -> std::io::Result<()> {
    // Set the fixed chunk size to 250 megabytes
    let file_iter = FileIter::new("file.bin")?.set_mode(ChunkSize::Bytes(
        SIUnit::new(250.0, SISize::Megabyte).into(),
    ));

    for chunk in file_iter {
        match chunk {
            Ok(data) => {
                // Some calculations with chunk
                // .....
            }
            Err(_) => break,
        }
    }
    Ok(())
}
Source

pub fn auto(bytes: f64) -> SIUnit

Converts a byte size into the appropriate International System of Units (SI) unit.

This function is part of the SIUnit enum and supports units such as Byte, Kilobyte, Megabyte, Gigabyte, Terabyte, Petabyte, Exabyte, and Overflow. The conversion is based on the SI standard for decimal prefixes.

§Arguments
  • bytes - A positive f64 representing the size in bytes.
§Returns
  • An SIUnit enum representing the converted size.
§Example
use get_chunk::data_size_format::si::SIUnit;
use get_chunk::iterator::FileIter;

fn main() -> std::io::Result<()> {
    let file_iter = FileIter::new("file.bin")?;

    // Display format
    println!("{}", SIUnit::auto(file_iter.get_file_size()));
    // Output: 54.08 GB

    // Debug format ( `debug` attribute is required )
    println!("{:?}", SIUnit::auto(file_iter.get_file_size()));
    // Output: Gigabyte(54.081281708, 54081281708.0)

    Ok(())
}
Source

pub fn get_values(&self) -> (f64, f64)

Retrieves the numeric values associated with an instance of the SIUnit enum.

§Returns

A tuple (value_h, value_b) representing the high-level numeric value and its equivalent in bytes.

Trait Implementations§

Source§

impl Add for SIUnit

Source§

type Output = SIUnit

The resulting type after applying the + operator.
Source§

fn add(self, other: SIUnit) -> SIUnit

Performs the + operation. Read more
Source§

impl Clone for SIUnit

Source§

fn clone(&self) -> SIUnit

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SIUnit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SIUnit

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for SIUnit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<f64> for SIUnit

Source§

type Output = SIUnit

The resulting type after applying the / operator.
Source§

fn div(self, divisor: f64) -> SIUnit

Performs the / operation. Read more
Source§

impl From<IECUnit> for SIUnit

Source§

fn from(iec_unit: IECUnit) -> Self

Converts to this type from the input type.
Source§

impl From<SIUnit> for IECUnit

Source§

fn from(si_unit: SIUnit) -> Self

Converts to this type from the input type.
Source§

impl From<SIUnit> for f64

Source§

fn from(data_size_unit: SIUnit) -> Self

Converts to this type from the input type.
Source§

impl From<SIUnit> for usize

Converts an SIUnit to a usize value.

Source§

fn from(data_size_unit: SIUnit) -> Self

Warning: This conversion may result in data loss.

Source§

impl IntoEnumIterator for SIUnit

Source§

impl Mul<f64> for SIUnit

Source§

type Output = SIUnit

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: f64) -> SIUnit

Performs the * operation. Read more
Source§

impl PartialEq for SIUnit

Source§

fn eq(&self, other: &SIUnit) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for SIUnit

Source§

fn partial_cmp(&self, other: &SIUnit) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub for SIUnit

Source§

type Output = SIUnit

The resulting type after applying the - operator.
Source§

fn sub(self, other: SIUnit) -> SIUnit

Performs the - operation. Read more
Source§

impl Copy for SIUnit

Source§

impl StructuralPartialEq for SIUnit

Auto Trait Implementations§

§

impl Freeze for SIUnit

§

impl RefUnwindSafe for SIUnit

§

impl Send for SIUnit

§

impl Sync for SIUnit

§

impl Unpin for SIUnit

§

impl UnwindSafe for SIUnit

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.