@@ -3,7 +3,7 @@ use std::io::Write;
3
3
use crate :: language:: SupportedLanguage ;
4
4
use crate :: parser:: ParsedData ;
5
5
use crate :: rename:: RenameExt ;
6
- use crate :: rust_types:: { RustItem , RustTypeFormatError , SpecialRustType } ;
6
+ use crate :: rust_types:: { RustConst , RustConstExpr , RustItem , RustTypeFormatError , SpecialRustType } ;
7
7
use crate :: {
8
8
language:: Language ,
9
9
rust_types:: { RustEnum , RustEnumVariant , RustField , RustStruct , RustTypeAlias } ,
@@ -58,6 +58,7 @@ impl Language for Go {
58
58
structs,
59
59
enums,
60
60
aliases,
61
+ consts,
61
62
..
62
63
} = data;
63
64
@@ -66,6 +67,7 @@ impl Language for Go {
66
67
. map ( RustItem :: Alias )
67
68
. chain ( structs. into_iter ( ) . map ( RustItem :: Struct ) )
68
69
. chain ( enums. into_iter ( ) . map ( RustItem :: Enum ) )
70
+ . chain ( consts. into_iter ( ) . map ( RustItem :: Const ) )
69
71
. collect :: < Vec < _ > > ( ) ;
70
72
71
73
topsort ( & mut items) ;
@@ -96,6 +98,7 @@ impl Language for Go {
96
98
RustItem :: Enum ( e) => self . write_enum ( w, e, & types_mapping_to_struct) ?,
97
99
RustItem :: Struct ( s) => self . write_struct ( w, s) ?,
98
100
RustItem :: Alias ( a) => self . write_type_alias ( w, a) ?,
101
+ RustItem :: Const ( c) => self . write_const ( w, c) ?,
99
102
}
100
103
}
101
104
@@ -189,6 +192,23 @@ impl Language for Go {
189
192
Ok ( ( ) )
190
193
}
191
194
195
+ fn write_const ( & mut self , w : & mut dyn Write , c : & RustConst ) -> std:: io:: Result < ( ) > {
196
+ match c. expr {
197
+ RustConstExpr :: Int ( val) => {
198
+ let const_type = self
199
+ . format_type ( & c. r#type , & [ ] )
200
+ . map_err ( |e| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , e) ) ?;
201
+ writeln ! (
202
+ w,
203
+ "const {} {} = {}" ,
204
+ c. id. renamed. to_pascal_case( ) ,
205
+ const_type,
206
+ val
207
+ )
208
+ }
209
+ }
210
+ }
211
+
192
212
fn write_struct ( & mut self , w : & mut dyn Write , rs : & RustStruct ) -> std:: io:: Result < ( ) > {
193
213
write_comments ( w, 0 , & rs. comments ) ?;
194
214
// TODO: Support generic bounds: https://github.com/1Password/typeshare/issues/222
0 commit comments