byte_unit/bit/adjusted/
built_in_traits.rs

1use core::str::FromStr;
2
3use super::{AdjustedBit, Bit, Unit, UnitType};
4use crate::ParseError;
5
6impl From<Bit> for AdjustedBit {
7    /// `unit_type` is set to `UnitType::Both`. See [`Bit::get_appropriate_unit`](./struct.Bit.html#method.get_appropriate_unit).
8    #[inline]
9    fn from(value: Bit) -> Self {
10        value.get_appropriate_unit(UnitType::Both)
11    }
12}
13
14impl From<AdjustedBit> for f64 {
15    #[inline]
16    fn from(value: AdjustedBit) -> Self {
17        value.get_value()
18    }
19}
20
21impl From<AdjustedBit> for Unit {
22    #[inline]
23    fn from(value: AdjustedBit) -> Self {
24        value.get_unit()
25    }
26}
27
28impl From<AdjustedBit> for Bit {
29    #[inline]
30    fn from(value: AdjustedBit) -> Self {
31        value.get_bit()
32    }
33}
34
35impl FromStr for AdjustedBit {
36    type Err = ParseError;
37
38    /// * `unit_type` is set to `UnitType::Both`. See [`Bit::get_appropriate_unit`](./struct.Bit.html#method.get_appropriate_unit).
39    #[inline]
40    fn from_str(s: &str) -> Result<Self, Self::Err> {
41        Ok(Bit::parse_str(s)?.get_appropriate_unit(UnitType::Both))
42    }
43}