File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,6 +72,12 @@ impl Enum {
7272 self
7373 }
7474
75+ /// Add an arbitrary macro.
76+ pub fn r#macro ( & mut self , r#macro : & str ) -> & mut Self {
77+ self . type_def . r#macro ( r#macro) ;
78+ self
79+ }
80+
7581 /// Push a variant to the enum, returning a mutable reference to it.
7682 pub fn new_variant ( & mut self , name : & str ) -> & mut Variant {
7783 self . push_variant ( Variant :: new ( name) ) ;
Original file line number Diff line number Diff line change @@ -85,6 +85,12 @@ impl Struct {
8585 self
8686 }
8787
88+ /// Add an arbitrary macro.
89+ pub fn r#macro ( & mut self , r#macro : & str ) -> & mut Self {
90+ self . type_def . r#macro ( r#macro) ;
91+ self
92+ }
93+
8894 /// Push a named field to the struct.
8995 ///
9096 /// A struct can either set named fields with this function or tuple fields
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ use crate::r#type::Type;
1010pub struct Variant {
1111 name : String ,
1212 fields : Fields ,
13+ annotations : Vec < String > ,
1314}
1415
1516impl Variant {
@@ -18,6 +19,7 @@ impl Variant {
1819 Variant {
1920 name : name. to_string ( ) ,
2021 fields : Fields :: Empty ,
22+ annotations : Vec :: new ( ) ,
2123 }
2224 }
2325
@@ -36,8 +38,18 @@ impl Variant {
3638 self
3739 }
3840
41+ /// Add an anotation to the variant.
42+ pub fn annotation ( & mut self , annotation : & str ) -> & mut Self {
43+ self . annotations . push ( annotation. to_string ( ) ) ;
44+ self
45+ }
46+
3947 /// Formats the variant using the given formatter.
4048 pub fn fmt ( & self , fmt : & mut Formatter < ' _ > ) -> fmt:: Result {
49+ for a in & self . annotations {
50+ write ! ( fmt, "{}" , a) ?;
51+ write ! ( fmt, "\n " ) ?;
52+ }
4153 write ! ( fmt, "{}" , self . name) ?;
4254 self . fields . fmt ( fmt) ?;
4355 write ! ( fmt, ",\n " ) ?;
You can’t perform that action at this time.
0 commit comments