Struct byte_unit::AdjustedBit
source · pub struct AdjustedBit { /* private fields */ }
Available on crate feature
bit
only.Expand description
Generated from the Bit::get_adjusted_unit
method or the the Bit::get_appropriate_unit
method.
For accuracy representation, utilize the Bit
struct.
Implementations§
source§impl AdjustedBit
impl AdjustedBit
Methods for getting values.
sourcepub fn get_bit(&self) -> Bit
pub fn get_bit(&self) -> Bit
Create a new Bit
instance from this AdjustedBit
instance.
Examples
use byte_unit::{Bit, Unit};
let bit = Bit::from_u64_with_unit(1555, Unit::Kbit).unwrap();
let adjusted_bit = bit.get_adjusted_unit(Unit::Mbit);
let bit_back = adjusted_bit.get_bit();
assert_eq!(bit, bit_back);
Points to Note
- The result may not be logically equal to the original
Bit
instance due to the accuracy of floating-point numbers.
Trait Implementations§
source§impl Clone for AdjustedBit
impl Clone for AdjustedBit
source§fn clone(&self) -> AdjustedBit
fn clone(&self) -> AdjustedBit
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 AdjustedBit
impl Debug for AdjustedBit
source§impl<'de> Deserialize<'de> for AdjustedBit
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for AdjustedBit
Available on crate feature
serde
only.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 AdjustedBit
impl Display for AdjustedBit
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter.
Examples
use byte_unit::{Bit, Unit};
let bit = Bit::from_u64_with_unit(1555, Unit::Kbit).unwrap();
let adjusted_bit = bit.get_adjusted_unit(Unit::Mbit);
assert_eq!("1.555 Mb", adjusted_bit.to_string());
use byte_unit::{Bit, UnitType};
let bit = Bit::from_u64(10000);
let adjusted_bit_based_2 = bit.get_appropriate_unit(UnitType::Binary);
let adjusted_bit_based_10 = bit.get_appropriate_unit(UnitType::Decimal);
assert_eq!("9.765625 Kib", format!("{adjusted_bit_based_2}"));
assert_eq!("10 Kb", format!("{adjusted_bit_based_10}"));
// with precision
assert_eq!("9.77 Kib", format!("{adjusted_bit_based_2:.2}"));
assert_eq!("10.00 Kb", format!("{adjusted_bit_based_10:.2}"));
// without any unnecessary fractional part
assert_eq!("9.77 Kib", format!("{adjusted_bit_based_2:#.2}"));
assert_eq!("10 Kb", format!("{adjusted_bit_based_10:#.2}"));
// with a width, left alignment
assert_eq!("9.77 Kib", format!("{adjusted_bit_based_2:10.2}"));
assert_eq!("10.00 Kb", format!("{adjusted_bit_based_10:10.2}"));
// with a width, right alignment
assert_eq!(" 9.77 Kib", format!("{adjusted_bit_based_2:>10.2}"));
assert_eq!(" 10.00 Kb", format!("{adjusted_bit_based_10:>10.2}"));
// with a width, right alignment, more spaces between the value and the unit
assert_eq!(" 9.77 Kib", format!("{adjusted_bit_based_2:>+10.2}"));
assert_eq!(" 10.00 Kb", format!("{adjusted_bit_based_10:>+10.2}"));
// no spaces between the value and the unit
assert_eq!("9.765625Kib", format!("{adjusted_bit_based_2:-}"));
assert_eq!("10Kb", format!("{adjusted_bit_based_10:-}"));
source§impl From<AdjustedBit> for Bit
impl From<AdjustedBit> for Bit
source§fn from(value: AdjustedBit) -> Self
fn from(value: AdjustedBit) -> Self
Converts to this type from the input type.
source§impl From<AdjustedBit> for Unit
impl From<AdjustedBit> for Unit
source§fn from(value: AdjustedBit) -> Self
fn from(value: AdjustedBit) -> Self
Converts to this type from the input type.
source§impl From<AdjustedBit> for f64
impl From<AdjustedBit> for f64
source§fn from(value: AdjustedBit) -> Self
fn from(value: AdjustedBit) -> Self
Converts to this type from the input type.
source§impl From<Bit> for AdjustedBit
impl From<Bit> for AdjustedBit
source§fn from(value: Bit) -> Self
fn from(value: Bit) -> Self
unit_type
is set to UnitType::Both
. See Bit::get_appropriate_unit
.
source§impl FromStr for AdjustedBit
impl FromStr for AdjustedBit
source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
unit_type
is set toUnitType::Both
. SeeBit::get_appropriate_unit
.
§type Err = ParseError
type Err = ParseError
The associated error which can be returned from parsing.
source§impl Ord for AdjustedBit
impl Ord for AdjustedBit
source§fn cmp(&self, other: &AdjustedBit) -> Ordering
fn cmp(&self, other: &AdjustedBit) -> Ordering
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 for AdjustedBit
impl PartialEq for AdjustedBit
source§fn eq(&self, other: &AdjustedBit) -> bool
fn eq(&self, other: &AdjustedBit) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for AdjustedBit
impl PartialOrd for AdjustedBit
source§fn partial_cmp(&self, other: &AdjustedBit) -> Option<Ordering>
fn partial_cmp(&self, other: &AdjustedBit) -> 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 moresource§impl Serialize for AdjustedBit
Available on crate feature serde
only.
impl Serialize for AdjustedBit
Available on crate feature
serde
only.impl Copy for AdjustedBit
impl Eq for AdjustedBit
Auto Trait Implementations§
impl RefUnwindSafe for AdjustedBit
impl Send for AdjustedBit
impl Sync for AdjustedBit
impl Unpin for AdjustedBit
impl UnwindSafe for AdjustedBit
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
Mutably borrows from an owned value. Read more