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§
source§impl 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§
source§impl Clone for AdjustedByte
impl Clone for AdjustedByte
source§fn clone(&self) -> AdjustedByte
fn clone(&self) -> AdjustedByte
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for AdjustedByte
impl Debug for AdjustedByte
source§impl<'de> Deserialize<'de> for AdjustedByte
impl<'de> Deserialize<'de> for AdjustedByte
source§fn 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
source§impl Display for AdjustedByte
impl Display for AdjustedByte
source§impl From<AdjustedByte> for Byte
impl From<AdjustedByte> for Byte
source§fn from(other: AdjustedByte) -> Byte
fn from(other: AdjustedByte) -> Byte
Converts to this type from the input type.
source§impl Ord for AdjustedByte
impl Ord for AdjustedByte
source§fn 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 · source§fn 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
source§impl PartialEq<AdjustedByte> for AdjustedByte
impl PartialEq<AdjustedByte> for AdjustedByte
source§fn 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));
source§impl PartialOrd<AdjustedByte> for AdjustedByte
impl PartialOrd<AdjustedByte> for AdjustedByte
source§fn partial_cmp(&self, other: &AdjustedByte) -> Option<Ordering>
fn partial_cmp(&self, other: &AdjustedByte) -> Option<Ordering>
1.0.0 · source§fn 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