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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use arrayvec::ArrayString;
use crate::constants::{MAX_INF_LEN, MAX_MIN_LEN, MAX_NAN_LEN};
use crate::format::utils::{InfinityStr, MinusSignStr, NanStr};
use crate::format::{CustomFormatBuilder, Format, Grouping};
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub struct CustomFormat {
pub(crate) dec: char,
pub(crate) grp: Grouping,
pub(crate) inf: ArrayString<[u8; MAX_INF_LEN]>,
pub(crate) min: ArrayString<[u8; MAX_MIN_LEN]>,
pub(crate) nan: ArrayString<[u8; MAX_NAN_LEN]>,
pub(crate) sep: Option<char>,
}
impl CustomFormat {
pub fn builder() -> CustomFormatBuilder {
CustomFormatBuilder::new()
}
pub fn into_builder(self) -> CustomFormatBuilder {
self.into()
}
pub fn decimal(&self) -> char {
self.dec
}
pub fn grouping(&self) -> Grouping {
self.grp
}
pub fn infinity(&self) -> &str {
&self.inf
}
pub fn minus_sign(&self) -> &str {
&self.min
}
pub fn nan(&self) -> &str {
&self.nan
}
pub fn separator(&self) -> Option<char> {
self.sep
}
}
impl Format for CustomFormat {
fn decimal(&self) -> char {
self.decimal()
}
fn grouping(&self) -> Grouping {
self.grouping()
}
fn infinity(&self) -> InfinityStr<'_> {
InfinityStr::new(self.infinity()).unwrap()
}
fn minus_sign(&self) -> MinusSignStr<'_> {
MinusSignStr::new(self.minus_sign()).unwrap()
}
fn nan(&self) -> NanStr<'_> {
NanStr::new(self.nan()).unwrap()
}
fn separator(&self) -> Option<char> {
self.separator()
}
}