1
1
//! Serialization options.
2
2
3
3
/// [`Options`] builder.
4
- pub struct OptionsBuilder ( Options ) ;
4
+ pub struct Builder ( Options ) ;
5
5
6
6
const DEFAULT : Options = ( ByteOrder :: NATIVE as Options ) << BYTEORDER_BIT ;
7
7
8
8
/// Start building new options.
9
9
///
10
- /// Call [`OptionsBuilder ::build`] to construct them.
11
- pub const fn new ( ) -> OptionsBuilder {
12
- OptionsBuilder ( DEFAULT )
10
+ /// Call [`Builder ::build`] to construct them.
11
+ pub const fn new ( ) -> Builder {
12
+ Builder ( DEFAULT )
13
13
}
14
14
15
15
/// Type encapsulating a static options for an encoding.
@@ -31,7 +31,7 @@ const MAP_KEYS_AS_NUMBERS_BIT: Options = 3;
31
31
const FLOAT_BIT : Options = 8 ;
32
32
const LENGTH_WIDTH_BIT : Options = 16 ;
33
33
34
- impl OptionsBuilder {
34
+ impl Builder {
35
35
/// Indicates if an integer serialization should be variable.
36
36
#[ inline( always) ]
37
37
pub const fn with_integer ( self , integer : Integer ) -> Self {
@@ -83,33 +83,55 @@ impl OptionsBuilder {
83
83
}
84
84
}
85
85
86
- #[ doc( hidden) ]
87
- pub const fn integer < const OPT : Options > ( ) -> Integer {
86
+ #[ cfg( any(
87
+ feature = "storage" ,
88
+ feature = "wire" ,
89
+ feature = "descriptive" ,
90
+ feature = "json" ,
91
+ feature = "value"
92
+ ) ) ]
93
+ #[ inline( always) ]
94
+ pub ( crate ) const fn integer < const OPT : Options > ( ) -> Integer {
88
95
match ( OPT >> INTEGER_BIT ) & 0b1 {
89
96
0 => Integer :: Variable ,
90
97
_ => Integer :: Fixed ,
91
98
}
92
99
}
93
100
94
- #[ doc( hidden) ]
95
- pub const fn float < const OPT : Options > ( ) -> Float {
101
+ #[ cfg( test) ]
102
+ #[ inline( always) ]
103
+ pub ( crate ) const fn float < const OPT : Options > ( ) -> Float {
96
104
match ( OPT >> FLOAT_BIT ) & 0b11 {
97
105
0 => Float :: Integer ,
98
106
1 => Float :: Variable ,
99
107
_ => Float :: Fixed ,
100
108
}
101
109
}
102
110
103
- #[ doc( hidden) ]
104
- pub const fn length < const OPT : Options > ( ) -> Integer {
111
+ #[ cfg( any(
112
+ feature = "storage" ,
113
+ feature = "wire" ,
114
+ feature = "descriptive" ,
115
+ feature = "json" ,
116
+ feature = "value"
117
+ ) ) ]
118
+ #[ inline( always) ]
119
+ pub ( crate ) const fn length < const OPT : Options > ( ) -> Integer {
105
120
match ( OPT >> LENGTH_BIT ) & 0b1 {
106
121
0 => Integer :: Variable ,
107
122
_ => Integer :: Fixed ,
108
123
}
109
124
}
110
125
111
- #[ doc( hidden) ]
112
- pub const fn length_width < const OPT : Options > ( ) -> Width {
126
+ #[ cfg( any(
127
+ feature = "storage" ,
128
+ feature = "wire" ,
129
+ feature = "descriptive" ,
130
+ feature = "json" ,
131
+ feature = "value"
132
+ ) ) ]
133
+ #[ inline( always) ]
134
+ pub ( crate ) const fn length_width < const OPT : Options > ( ) -> Width {
113
135
match ( OPT >> LENGTH_WIDTH_BIT ) & 0b11 {
114
136
0 => Width :: U8 ,
115
137
1 => Width :: U16 ,
@@ -118,16 +140,24 @@ pub const fn length_width<const OPT: Options>() -> Width {
118
140
}
119
141
}
120
142
121
- #[ doc( hidden) ]
122
- pub const fn byteorder < const OPT : Options > ( ) -> ByteOrder {
143
+ #[ cfg( any(
144
+ feature = "storage" ,
145
+ feature = "wire" ,
146
+ feature = "descriptive" ,
147
+ feature = "json" ,
148
+ feature = "value"
149
+ ) ) ]
150
+ #[ inline( always) ]
151
+ pub ( crate ) const fn byteorder < const OPT : Options > ( ) -> ByteOrder {
123
152
match ( OPT >> BYTEORDER_BIT ) & 0b1 {
124
- 0 => ByteOrder :: LittleEndian ,
125
- _ => ByteOrder :: BigEndian ,
153
+ 0 => ByteOrder :: Little ,
154
+ _ => ByteOrder :: Big ,
126
155
}
127
156
}
128
157
129
- #[ doc( hidden) ]
130
- pub const fn is_map_keys_as_numbers < const OPT : Options > ( ) -> bool {
158
+ #[ cfg( all( feature = "alloc" , feature = "value" ) ) ]
159
+ #[ inline( always) ]
160
+ pub ( crate ) const fn is_map_keys_as_numbers < const OPT : Options > ( ) -> bool {
131
161
( ( OPT >> MAP_KEYS_AS_NUMBERS_BIT ) & 0b1 ) == 1
132
162
}
133
163
@@ -156,28 +186,40 @@ pub enum Float {
156
186
Fixed = 2 ,
157
187
}
158
188
159
- /// Byte order.
189
+ /// Byte order to use when encoding numbers.
190
+ ///
191
+ /// By default, this is the [`ByteOrder::NATIVE`] byte order of the target
192
+ /// platform.
160
193
#[ derive( PartialEq , Eq ) ]
161
194
#[ cfg_attr( test, derive( Debug ) ) ]
162
195
#[ repr( u8 ) ]
163
196
#[ non_exhaustive]
164
197
pub enum ByteOrder {
165
198
/// Little endian byte order.
166
- LittleEndian = 0 ,
199
+ Little = 0 ,
167
200
/// Big endian byte order.
168
- BigEndian = 1 ,
201
+ Big = 1 ,
169
202
}
170
203
171
204
impl ByteOrder {
172
205
/// The native byte order.
206
+ ///
207
+ /// [`Little`] for little and [`Big`] for big endian platforms.
208
+ ///
209
+ /// [`Little`]: ByteOrder::Little
210
+ /// [`Big`]: ByteOrder::Big
173
211
pub const NATIVE : Self = if cfg ! ( target_endian = "little" ) {
174
- Self :: LittleEndian
212
+ Self :: Little
175
213
} else {
176
- Self :: BigEndian
214
+ Self :: Big
177
215
} ;
178
216
179
217
/// The network byte order.
180
- pub const NETWORK : Self = Self :: BigEndian ;
218
+ ///
219
+ /// This is the same as [`Big`].
220
+ ///
221
+ /// [`Big`]: ByteOrder::Big
222
+ pub const NETWORK : Self = Self :: Big ;
181
223
}
182
224
183
225
#[ doc( hidden) ]
@@ -307,14 +349,14 @@ fn test_builds() {
307
349
}
308
350
309
351
test_case ! {
310
- self :: new( ) . with_byte_order( ByteOrder :: BigEndian ) => {
311
- byteorder = ByteOrder :: BigEndian ,
352
+ self :: new( ) . with_byte_order( ByteOrder :: Big ) => {
353
+ byteorder = ByteOrder :: Big ,
312
354
}
313
355
}
314
356
315
357
test_case ! {
316
- self :: new( ) . with_byte_order( ByteOrder :: LittleEndian ) => {
317
- byteorder = ByteOrder :: LittleEndian ,
358
+ self :: new( ) . with_byte_order( ByteOrder :: Little ) => {
359
+ byteorder = ByteOrder :: Little ,
318
360
}
319
361
}
320
362
0 commit comments