@@ -7,11 +7,13 @@ use crate::{
77 Schema ,
88} ;
99use core:: {
10+ marker:: PhantomData ,
1011 num:: {
1112 NonZeroI128 , NonZeroI16 , NonZeroI32 , NonZeroI64 , NonZeroI8 , NonZeroU128 , NonZeroU16 ,
1213 NonZeroU32 , NonZeroU64 , NonZeroU8 ,
1314 } ,
1415 ops:: { Range , RangeFrom , RangeInclusive , RangeTo } ,
16+ time:: Duration ,
1517} ;
1618
1719macro_rules! impl_schema {
@@ -155,3 +157,134 @@ impl<T: Schema> Schema for RangeTo<T> {
155157 } ] ) ,
156158 } ;
157159}
160+
161+ #[ cfg_attr( docsrs, doc( cfg( feature = "core-net" ) ) ) ]
162+ impl Schema for core:: net:: Ipv4Addr {
163+ const SCHEMA : & ' static NamedType = & NamedType {
164+ name : "Ipv4Addr" ,
165+ ty : & DataModelType :: Struct ( & [ & NamedValue {
166+ name : "octets" ,
167+ ty : <[ u8 ; 4 ] >:: SCHEMA ,
168+ } ] ) ,
169+ } ;
170+ }
171+
172+ #[ cfg_attr( docsrs, doc( cfg( feature = "core-net" ) ) ) ]
173+ impl Schema for core:: net:: Ipv6Addr {
174+ const SCHEMA : & ' static NamedType = & NamedType {
175+ name : "Ipv6Addr" ,
176+ ty : & DataModelType :: Struct ( & [ & NamedValue {
177+ name : "octets" ,
178+ ty : <[ u8 ; 16 ] >:: SCHEMA ,
179+ } ] ) ,
180+ } ;
181+ }
182+
183+ #[ cfg_attr( docsrs, doc( cfg( feature = "core-net" ) ) ) ]
184+ impl Schema for core:: net:: IpAddr {
185+ const SCHEMA : & ' static NamedType = & NamedType {
186+ name : "IpAddr" ,
187+ ty : & DataModelType :: Enum ( & [
188+ & NamedVariant {
189+ name : "V4" ,
190+ ty : & DataModelVariant :: NewtypeVariant ( core:: net:: Ipv4Addr :: SCHEMA ) ,
191+ } ,
192+ & NamedVariant {
193+ name : "V6" ,
194+ ty : & DataModelVariant :: NewtypeVariant ( core:: net:: Ipv6Addr :: SCHEMA ) ,
195+ } ,
196+ ] ) ,
197+ } ;
198+ }
199+
200+ #[ cfg_attr( docsrs, doc( cfg( feature = "core-net" ) ) ) ]
201+ impl Schema for core:: net:: SocketAddrV4 {
202+ const SCHEMA : & ' static NamedType = & NamedType {
203+ name : "SocketAddrV4" ,
204+ ty : & DataModelType :: Struct ( & [
205+ & NamedValue {
206+ name : "ip" ,
207+ ty : core:: net:: Ipv4Addr :: SCHEMA ,
208+ } ,
209+ & NamedValue {
210+ name : "port" ,
211+ ty : u16:: SCHEMA ,
212+ } ,
213+ ] ) ,
214+ } ;
215+ }
216+
217+ #[ cfg_attr( docsrs, doc( cfg( feature = "core-net" ) ) ) ]
218+ impl Schema for core:: net:: SocketAddrV6 {
219+ const SCHEMA : & ' static NamedType = & NamedType {
220+ name : "SocketAddrV6" ,
221+ ty : & DataModelType :: Struct ( & [
222+ & NamedValue {
223+ name : "ip" ,
224+ ty : core:: net:: Ipv6Addr :: SCHEMA ,
225+ } ,
226+ & NamedValue {
227+ name : "port" ,
228+ ty : u16:: SCHEMA ,
229+ } ,
230+ & NamedValue {
231+ name : "flowinfo" ,
232+ ty : u32:: SCHEMA ,
233+ } ,
234+ & NamedValue {
235+ name : "scope_id" ,
236+ ty : u32:: SCHEMA ,
237+ } ,
238+ ] ) ,
239+ } ;
240+ }
241+
242+ #[ cfg_attr( docsrs, doc( cfg( feature = "core-net" ) ) ) ]
243+ impl Schema for core:: net:: SocketAddr {
244+ const SCHEMA : & ' static NamedType = & NamedType {
245+ name : "SocketAddr" ,
246+ ty : & DataModelType :: Enum ( & [
247+ & NamedVariant {
248+ name : "V4" ,
249+ ty : & DataModelVariant :: NewtypeVariant ( core:: net:: SocketAddrV4 :: SCHEMA ) ,
250+ } ,
251+ & NamedVariant {
252+ name : "V6" ,
253+ ty : & DataModelVariant :: NewtypeVariant ( core:: net:: SocketAddrV6 :: SCHEMA ) ,
254+ } ,
255+ ] ) ,
256+ } ;
257+ }
258+
259+ impl < T : Schema > Schema for core:: num:: Wrapping < T > {
260+ const SCHEMA : & ' static NamedType = T :: SCHEMA ;
261+ }
262+
263+ #[ cfg( feature = "core-num-saturating" ) ]
264+ #[ cfg_attr( docsrs, doc( cfg( feature = "core-num-saturating" ) ) ) ]
265+ impl < T : Schema > Schema for core:: num:: Saturating < T > {
266+ const SCHEMA : & ' static NamedType = T :: SCHEMA ;
267+ }
268+
269+ impl Schema for Duration {
270+ const SCHEMA : & ' static NamedType = & NamedType {
271+ name : "Duration" ,
272+ ty : & DataModelType :: Struct ( & [
273+ & NamedValue {
274+ name : "secs" ,
275+ ty : u64:: SCHEMA ,
276+ } ,
277+ & NamedValue {
278+ name : "nanos" ,
279+ ty : u32:: SCHEMA ,
280+ } ,
281+ ] ) ,
282+ } ;
283+ }
284+
285+ impl < T : ?Sized > Schema for PhantomData < T > {
286+ const SCHEMA : & ' static NamedType = & NamedType {
287+ name : "PhantomData" ,
288+ ty : & DataModelType :: Unit ,
289+ } ;
290+ }
0 commit comments