byte_unit/unit/built_in_trait.rs
1use core::str::FromStr;
2
3use super::Unit;
4use crate::UnitParseError;
5
6impl FromStr for Unit {
7 type Err = UnitParseError;
8
9 /// `ignore_case` is set to `false`; `prefer_byte` is set to `true`. See [`Unit::parse_str`](#method.parse_str).
10 #[inline]
11 fn from_str(s: &str) -> Result<Self, Self::Err> {
12 Unit::parse_str(s, false, true)
13 }
14}
15
16impl From<Unit> for u128 {
17 /// See [`Unit::as_bits_u128`](#method.as_bits_u128).
18 #[inline]
19 fn from(unit: Unit) -> Self {
20 unit.as_bits_u128()
21 }
22}
23
24impl AsRef<str> for Unit {
25 #[inline]
26 fn as_ref(&self) -> &str {
27 self.as_str()
28 }
29}