byte_unit/byte/adjusted/
built_in_traits.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use core::str::FromStr;

use super::{AdjustedByte, Byte, Unit, UnitType};
use crate::ParseError;

impl From<Byte> for AdjustedByte {
    /// `unit_type` is set to `UnitType::Both`. See [`Byte::get_appropriate_unit`](./struct.Byte.html#method.get_appropriate_unit).
    #[inline]
    fn from(value: Byte) -> Self {
        value.get_appropriate_unit(UnitType::Both)
    }
}

impl From<AdjustedByte> for f64 {
    #[inline]
    fn from(value: AdjustedByte) -> Self {
        value.get_value()
    }
}

impl From<AdjustedByte> for Unit {
    #[inline]
    fn from(value: AdjustedByte) -> Self {
        value.get_unit()
    }
}

impl From<AdjustedByte> for Byte {
    #[inline]
    fn from(value: AdjustedByte) -> Self {
        value.get_byte()
    }
}

impl FromStr for AdjustedByte {
    type Err = ParseError;

    /// * `ignore_case` is set to `false`. See [`Byte::parse_str`](./struct.Byte.html#method.parse_str).
    /// * `unit_type` is set to `UnitType::Both`. See [`Byte::get_appropriate_unit`](./struct.Byte.html#method.get_appropriate_unit).
    #[inline]
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(Byte::parse_str(s, false)?.get_appropriate_unit(UnitType::Both))
    }
}