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 moresourceimpl Debug for AdjustedByte
impl Debug for AdjustedByte
sourceimpl<'de> Deserialize<'de> for AdjustedByte
impl<'de> Deserialize<'de> for AdjustedByte
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
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
Converts to this type from the input type.
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) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
Restrict a value to a certain interval. 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>
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 moresourceimpl Serialize for AdjustedByte
impl Serialize for AdjustedByte
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 Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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