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
use core::str::FromStr;

use super::Unit;
use crate::UnitParseError;

impl FromStr for Unit {
    type Err = UnitParseError;

    /// `ignore_case` is set to `false`; `prefer_byte` is set to `true`. See [`Unit::parse_str`](#method.parse_str).
    #[inline]
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Unit::parse_str(s, false, true)
    }
}

impl From<Unit> for u128 {
    /// See [`Unit::as_bits_u128`](#method.as_bits_u128).
    #[inline]
    fn from(unit: Unit) -> Self {
        unit.as_bits_u128()
    }
}

impl AsRef<str> for Unit {
    #[inline]
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}