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,
}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
impl SIUnit
Sourcepub fn new(value: f64, unit_type: SISize) -> SIUnit
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 positivef64representing the numeric value of the size.unit_type- AnSISizeenum specifying the unit type.
§Returns
- An
SIUnitenum 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(())
}Sourcepub fn auto(bytes: f64) -> SIUnit
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 positivef64representing the size in bytes.
§Returns
- An
SIUnitenum 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(())
}Sourcepub fn get_values(&self) -> (f64, f64)
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 IntoEnumIterator for SIUnit
impl IntoEnumIterator for SIUnit
type Iterator = SIUnitIter
fn iter() -> SIUnitIter ⓘ
Source§impl PartialOrd for SIUnit
impl PartialOrd for SIUnit
impl Copy for SIUnit
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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