2
2
3
3
use chrono:: DateTime ;
4
4
use mullvad_proc_macro:: { IntoProto , UnwrapProto } ;
5
+ use crate :: proto:: Timestamp ;
5
6
6
7
#[ derive( Debug ) ]
7
8
struct RelaySettings ;
@@ -85,12 +86,24 @@ impl IntoProto<proto::Timestamp> for chrono::DateTime<chrono::Utc> {
85
86
}
86
87
}
87
88
89
+ impl FromProto < proto:: AppVersionInfo > for AppVersionInfo {
90
+ fn from_proto ( other : proto:: AppVersionInfo ) -> Self {
91
+ AppVersionInfo {
92
+ latest_beta : other. latest_beta ,
93
+ latest_stable : other. latest_stable ,
94
+ suggested_upgrade : other. suggested_upgrade ,
95
+ supported : other. supported ,
96
+ }
97
+ }
98
+ }
99
+
88
100
pub type AppVersion = String ;
89
101
90
102
mod proto {
91
- use mullvad_proc_macro:: IntoProto ;
103
+ use super :: FromProto ;
104
+ use mullvad_proc_macro:: { FromProto , IntoProto } ;
92
105
93
- #[ derive( Debug ) ]
106
+ #[ derive( Debug , FromProto ) ]
94
107
pub struct AppVersionInfo {
95
108
pub supported : bool ,
96
109
pub latest_stable : String ,
@@ -108,6 +121,16 @@ mod proto {
108
121
pub seconds : i64 ,
109
122
pub nanos : i32 ,
110
123
}
124
+
125
+ mod mullvad_types {
126
+ #[ derive( Debug ) ]
127
+ pub struct AppVersionInfo {
128
+ pub supported : bool ,
129
+ pub latest_stable : String ,
130
+ pub latest_beta : String ,
131
+ pub suggested_upgrade : Option < String > ,
132
+ }
133
+ }
111
134
}
112
135
113
136
trait IntoProto < T > {
@@ -120,6 +143,16 @@ impl<T: Into<S>, S> IntoProto<S> for T {
120
143
}
121
144
}
122
145
146
+ trait FromProto < T > {
147
+ fn from_proto ( other : T ) -> Self ;
148
+ }
149
+
150
+ impl < T : From < S > , S > FromProto < S > for T {
151
+ fn from_proto ( other : S ) -> Self {
152
+ Self :: from ( other)
153
+ }
154
+ }
155
+
123
156
#[ test]
124
157
fn test_generate_into_proto ( ) {
125
158
let settings_proto = AppVersionInfo {
0 commit comments