@@ -18,11 +18,6 @@ use core::marker::PhantomData;
18
18
use core:: mem:: MaybeUninit ;
19
19
use core:: num:: * ;
20
20
21
- #[ cfg( feature = "std" ) ]
22
- use core:: hash:: { BuildHasher , Hash } ;
23
- #[ cfg( feature = "std" ) ]
24
- use std:: collections:: { HashMap , HashSet } ;
25
-
26
21
macro_rules! impl_both {
27
22
( $t: ty, $encoder: ident, $decoder: ident) => {
28
23
impl Encode for $t {
@@ -33,6 +28,7 @@ macro_rules! impl_both {
33
28
}
34
29
} ;
35
30
}
31
+ pub ( crate ) use impl_both;
36
32
impl_both ! ( bool , BoolEncoder , BoolDecoder ) ;
37
33
impl_both ! ( f32 , F32Encoder , F32Decoder ) ;
38
34
impl_both ! ( String , StrEncoder , StrDecoder ) ;
@@ -150,31 +146,13 @@ impl<T: Encode> Encode for BTreeSet<T> {
150
146
impl < ' a , T : Decode < ' a > + Ord > Decode < ' a > for BTreeSet < T > {
151
147
type Decoder = VecDecoder < ' a , T > ;
152
148
}
153
- #[ cfg( feature = "std" ) ]
154
- impl < T : Encode , S > Encode for HashSet < T , S > {
155
- type Encoder = VecEncoder < T > ;
156
- }
157
- #[ cfg( feature = "std" ) ]
158
- impl < ' a , T : Decode < ' a > + Eq + Hash , S : BuildHasher + Default > Decode < ' a > for HashSet < T , S > {
159
- type Decoder = VecDecoder < ' a , T > ;
160
- }
161
149
162
150
impl < K : Encode , V : Encode > Encode for BTreeMap < K , V > {
163
151
type Encoder = MapEncoder < K , V > ;
164
152
}
165
153
impl < ' a , K : Decode < ' a > + Ord , V : Decode < ' a > > Decode < ' a > for BTreeMap < K , V > {
166
154
type Decoder = MapDecoder < ' a , K , V > ;
167
155
}
168
- #[ cfg( feature = "std" ) ]
169
- impl < K : Encode , V : Encode , S > Encode for HashMap < K , V , S > {
170
- type Encoder = MapEncoder < K , V > ;
171
- }
172
- #[ cfg( feature = "std" ) ]
173
- impl < ' a , K : Decode < ' a > + Eq + Hash , V : Decode < ' a > , S : BuildHasher + Default > Decode < ' a >
174
- for HashMap < K , V , S >
175
- {
176
- type Decoder = MapDecoder < ' a , K , V > ;
177
- }
178
156
179
157
impl < T : Encode , E : Encode > Encode for core:: result:: Result < T , E > {
180
158
type Encoder = ResultEncoder < T , E > ;
@@ -184,42 +162,49 @@ impl<'a, T: Decode<'a>, E: Decode<'a>> Decode<'a> for core::result::Result<T, E>
184
162
}
185
163
186
164
#[ cfg( feature = "std" ) ]
187
- macro_rules! impl_convert {
188
- ( $want: path, $have: ty) => {
189
- impl Encode for $want {
190
- type Encoder = super :: convert:: ConvertIntoEncoder <$have>;
191
- }
192
- impl <' a> Decode <' a> for $want {
193
- type Decoder = super :: convert:: ConvertFromDecoder <' a, $have>;
194
- }
195
- } ;
196
- }
165
+ mod with_std {
166
+ use super :: * ;
167
+ use crate :: derive:: convert:: impl_convert;
168
+ use core:: hash:: { BuildHasher , Hash } ;
169
+ use std:: collections:: { HashMap , HashSet } ;
170
+
171
+ impl < T : Encode , S > Encode for HashSet < T , S > {
172
+ type Encoder = VecEncoder < T > ;
173
+ }
174
+ impl < ' a , T : Decode < ' a > + Eq + Hash , S : BuildHasher + Default > Decode < ' a > for HashSet < T , S > {
175
+ type Decoder = VecDecoder < ' a , T > ;
176
+ }
177
+ impl < K : Encode , V : Encode , S > Encode for HashMap < K , V , S > {
178
+ type Encoder = MapEncoder < K , V > ;
179
+ }
180
+ impl < ' a , K : Decode < ' a > + Eq + Hash , V : Decode < ' a > , S : BuildHasher + Default > Decode < ' a >
181
+ for HashMap < K , V , S >
182
+ {
183
+ type Decoder = MapDecoder < ' a , K , V > ;
184
+ }
197
185
198
- #[ cfg( feature = "std" ) ]
199
- macro_rules! impl_ipvx_addr {
200
- ( $addr: ident, $repr: ident) => {
201
- impl_convert!( std:: net:: $addr, $repr) ;
202
- } ;
203
- }
186
+ macro_rules! impl_ipvx_addr {
187
+ ( $addr: ident, $repr: ident) => {
188
+ impl_convert!( std:: net:: $addr, $repr) ;
189
+ } ;
190
+ }
204
191
205
- #[ cfg( feature = "std" ) ]
206
- impl_ipvx_addr ! ( Ipv4Addr , u32 ) ;
207
- #[ cfg( feature = "std" ) ]
208
- impl_ipvx_addr ! ( Ipv6Addr , u128 ) ;
209
- #[ cfg( feature = "std" ) ]
210
- impl_convert ! ( std:: net:: IpAddr , super :: ip_addr:: IpAddrConversion ) ;
211
- #[ cfg( feature = "std" ) ]
212
- impl_convert ! (
213
- std:: net:: SocketAddrV4 ,
214
- super :: ip_addr:: SocketAddrV4Conversion
215
- ) ;
216
- #[ cfg( feature = "std" ) ]
217
- impl_convert ! (
218
- std:: net:: SocketAddrV6 ,
219
- super :: ip_addr:: SocketAddrV6Conversion
220
- ) ;
221
- #[ cfg( feature = "std" ) ]
222
- impl_convert ! ( std:: net:: SocketAddr , super :: ip_addr:: SocketAddrConversion ) ;
192
+ impl_ipvx_addr ! ( Ipv4Addr , u32 ) ;
193
+ impl_ipvx_addr ! ( Ipv6Addr , u128 ) ;
194
+ impl_convert ! ( std:: net:: IpAddr , crate :: derive:: ip_addr:: IpAddrConversion ) ;
195
+ impl_convert ! (
196
+ std:: net:: SocketAddrV4 ,
197
+ crate :: derive:: ip_addr:: SocketAddrV4Conversion
198
+ ) ;
199
+ impl_convert ! (
200
+ std:: net:: SocketAddrV6 ,
201
+ crate :: derive:: ip_addr:: SocketAddrV6Conversion
202
+ ) ;
203
+ impl_convert ! (
204
+ std:: net:: SocketAddr ,
205
+ crate :: derive:: ip_addr:: SocketAddrConversion
206
+ ) ;
207
+ }
223
208
224
209
impl < T > Encode for PhantomData < T > {
225
210
type Encoder = EmptyCoder ;
0 commit comments