Struct byte_unit::AdjustedByte
source · [−]pub struct AdjustedByte { /* private fields */ }
Expand description
Generated from the get_appropriate_unit
and get_adjusted_unit
methods of a Byte
object.
Implementations
sourceimpl AdjustedByte
impl AdjustedByte
sourcepub fn format(&self, fractional_digits: usize) -> String
pub fn format(&self, fractional_digits: usize) -> String
Format the AdjustedByte
object to string.
Examples
use byte_unit::{Byte, ByteUnit};
let byte = Byte::from_unit(1555f64, ByteUnit::KB).unwrap();
let result = byte.get_appropriate_unit(false).format(3);
assert_eq!("1.555 MB", result);
use byte_unit::{Byte, ByteUnit};
let byte = Byte::from_unit(1555.2f64, ByteUnit::B).unwrap();
let result = byte.get_adjusted_unit(ByteUnit::B).format(3);
assert_eq!("1555 B", result);
pub fn get_value(&self) -> f64
pub fn get_unit(&self) -> ByteUnit
sourcepub fn get_byte(&self) -> Byte
pub fn get_byte(&self) -> Byte
Create a new Byte
object from this AdjustedByte
object. Accuracy should be taken care of.
Examples
use byte_unit::{Byte, ByteUnit};
let byte = Byte::from_str("123456789123456").unwrap();
let adjusted_byte = byte.get_adjusted_unit(ByteUnit::GB);
assert_eq!(123456.789123456, adjusted_byte.get_value());
let byte = adjusted_byte.get_byte();
let adjusted_byte = byte.get_adjusted_unit(ByteUnit::GB);
assert_eq!(123456.789123, adjusted_byte.get_value());
Trait Implementations
sourceimpl Clone for AdjustedByte
impl Clone for AdjustedByte
sourcefn clone(&self) -> AdjustedByte
fn clone(&self) -> AdjustedByte
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for AdjustedByte
impl Debug for AdjustedByte
sourceimpl Display for AdjustedByte
impl Display for AdjustedByte
sourceimpl From<AdjustedByte> for Byte
impl From<AdjustedByte> for Byte
sourcefn from(other: AdjustedByte) -> Byte
fn from(other: AdjustedByte) -> Byte
Performs the conversion.
sourceimpl Ord for AdjustedByte
impl Ord for AdjustedByte
sourcefn cmp(&self, other: &AdjustedByte) -> Ordering
fn cmp(&self, other: &AdjustedByte) -> Ordering
Deal with the logical numeric comparation.
Examples
use byte_unit::{Byte, ByteUnit};
let byte1 = Byte::from_unit(1024f64, ByteUnit::KiB).unwrap();
let byte2 = Byte::from_unit(1025f64, ByteUnit::KiB).unwrap();
assert!(byte1.get_appropriate_unit(false) < byte2.get_appropriate_unit(true));
use byte_unit::{Byte, ByteUnit};
let byte1 = Byte::from_unit(1024f64, ByteUnit::KiB).unwrap();
let byte2 = Byte::from_unit(1.01f64, ByteUnit::MiB).unwrap();
assert!(byte1.get_appropriate_unit(true) < byte2.get_appropriate_unit(false));
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
sourceimpl PartialEq<AdjustedByte> for AdjustedByte
impl PartialEq<AdjustedByte> for AdjustedByte
sourcefn eq(&self, other: &AdjustedByte) -> bool
fn eq(&self, other: &AdjustedByte) -> bool
Deal with the logical numeric equivalent.
Examples
use byte_unit::{Byte, ByteUnit};
let byte1 = Byte::from_unit(1024f64, ByteUnit::KiB).unwrap();
let byte2 = Byte::from_unit(1024f64, ByteUnit::KiB).unwrap();
assert_eq!(byte1.get_appropriate_unit(false), byte2.get_appropriate_unit(true));
use byte_unit::{Byte, ByteUnit};
let byte1 = Byte::from_unit(1024f64, ByteUnit::KiB).unwrap();
let byte2 = Byte::from_unit(1f64, ByteUnit::MiB).unwrap();
assert_eq!(byte1.get_appropriate_unit(true), byte2.get_appropriate_unit(false));
sourceimpl PartialOrd<AdjustedByte> for AdjustedByte
impl PartialOrd<AdjustedByte> for AdjustedByte
sourcefn partial_cmp(&self, other: &AdjustedByte) -> Option<Ordering>
fn partial_cmp(&self, other: &AdjustedByte) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for AdjustedByte
impl Eq for AdjustedByte
Auto Trait Implementations
impl RefUnwindSafe for AdjustedByte
impl Send for AdjustedByte
impl Sync for AdjustedByte
impl Unpin for AdjustedByte
impl UnwindSafe for AdjustedByte
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more