1pub type FidlNumber = String;
7
8#[derive(Debug, Clone, PartialEq, Hash, Default, Eq)]
10pub struct Number(String);
11
12impl Number {
13 const NUMBER_FORMAT: i64 = 129;
16
17 pub fn type_(&self) -> i64 {
20 Number::NUMBER_FORMAT
21 }
22}
23
24impl From<Number> for String {
25 fn from(x: Number) -> Self {
26 x.0
27 }
28}
29
30impl From<&str> for Number {
31 fn from(n: &str) -> Self {
32 let inner = if n.starts_with("\"") && n.ends_with("\"") {
34 n.to_string()
35 } else {
36 format!("\"{}\"", n)
37 };
38 Self(inner)
39 }
40}
41
42impl From<FidlNumber> for Number {
43 fn from(n: FidlNumber) -> Self {
44 n.as_str().into()
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[fuchsia::test]
53 fn number_type_in_valid_range() {
54 let number = Number::from("1234567");
55 assert!(number.type_() >= 128);
57 assert!(number.type_() <= 175);
58 }
59
60 #[fuchsia::test]
61 fn number_str_roundtrip() {
62 let number = Number::from("1234567");
63 assert_eq!(number.clone(), Number::from(&*String::from(number)));
64 }
65}