1
1
#![ allow( unused) ]
2
+
3
+ use chrono:: DateTime ;
2
4
use mullvad_proc_macro:: { IntoProto , UnwrapProto } ;
3
5
4
6
#[ derive( Debug ) ]
@@ -69,40 +71,55 @@ pub struct AppVersionInfo {
69
71
pub suggested_upgrade : Option < String > ,
70
72
}
71
73
74
+ #[ derive( IntoProto , Debug ) ]
75
+ pub struct Device {
76
+ pub created : chrono:: DateTime < chrono:: Utc > ,
77
+ }
78
+
79
+ impl IntoProto < proto:: Timestamp > for chrono:: DateTime < chrono:: Utc > {
80
+ fn into_proto ( self ) -> proto:: Timestamp {
81
+ proto:: Timestamp {
82
+ seconds : self . timestamp ( ) ,
83
+ nanos : 0 ,
84
+ }
85
+ }
86
+ }
87
+
72
88
pub type AppVersion = String ;
73
89
74
90
mod proto {
91
+ use mullvad_proc_macro:: IntoProto ;
92
+
75
93
#[ derive( Debug ) ]
76
94
pub struct AppVersionInfo {
77
95
pub supported : bool ,
78
96
pub latest_stable : String ,
79
97
pub latest_beta : String ,
80
98
pub suggested_upgrade : Option < String > ,
81
99
}
100
+
101
+ #[ derive( Debug ) ]
102
+ pub struct Device {
103
+ pub created : Timestamp ,
104
+ }
105
+
106
+ #[ derive( Debug ) ]
107
+ pub struct Timestamp {
108
+ pub seconds : i64 ,
109
+ pub nanos : i32 ,
110
+ }
82
111
}
83
112
84
113
trait IntoProto < T > {
85
114
fn into_proto ( self ) -> T ;
86
115
}
87
- impl < T : IntoProto < S > , S > IntoProto < Option < S > > for Option < T > {
88
- fn into_proto ( self ) -> Option < S > {
89
- self . map ( |val| val. into_proto ( ) )
90
- }
91
- }
92
116
93
- macro_rules! impl_into_proto_for_value_type {
94
- ( $ty: ty) => {
95
- impl IntoProto <$ty> for $ty {
96
- fn into_proto( self ) -> $ty {
97
- self
98
- }
99
- }
100
- } ;
117
+ impl < T : Into < S > , S > IntoProto < S > for T {
118
+ fn into_proto ( self ) -> S {
119
+ self . into ( )
120
+ }
101
121
}
102
122
103
- impl_into_proto_for_value_type ! ( bool ) ;
104
- impl_into_proto_for_value_type ! ( String ) ;
105
-
106
123
#[ test]
107
124
fn test_generate_into_proto ( ) {
108
125
let settings_proto = AppVersionInfo {
@@ -112,6 +129,13 @@ fn test_generate_into_proto() {
112
129
supported : false ,
113
130
} ;
114
131
115
- let settings = settings_proto. into_proto ( ) ;
132
+ let settings: proto:: AppVersionInfo = settings_proto. into_proto ( ) ;
133
+ dbg ! ( settings) ;
134
+
135
+ let device_proto = Device {
136
+ created : DateTime :: default ( ) ,
137
+ } ;
138
+
139
+ let settings: proto:: Device = device_proto. into_proto ( ) ;
116
140
dbg ! ( settings) ;
117
141
}
0 commit comments