File tree 4 files changed +43
-1
lines changed
4 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ owo-colors.workspace = true
13
13
prettyplease = { workspace = true , features = [" verbatim" ] }
14
14
proc-macro2.workspace = true
15
15
regex.workspace = true
16
+ serde.workspace = true
16
17
shlex.workspace = true
17
18
similar = { workspace = true , features = [" inline" ] }
18
19
syn.workspace = true
Original file line number Diff line number Diff line change
1
+ // bindgen-flags: --no-layout-tests
2
+ // bindgen-parse-callbacks: derive-transparent-serialize=color
3
+ typedef struct {
4
+ int red ;
5
+ int green ;
6
+ int blue ;
7
+ } color ;
Original file line number Diff line number Diff line change @@ -146,6 +146,27 @@ impl ParseCallbacks for WrapAsVariadicFn {
146
146
}
147
147
}
148
148
149
+ #[ derive( Debug ) ]
150
+ struct DeriveTransparentSerialize ( String ) ;
151
+
152
+ impl ParseCallbacks for DeriveTransparentSerialize {
153
+ fn add_derives ( & self , info : & DeriveInfo < ' _ > ) -> Vec < String > {
154
+ if info. name == & self . 0 {
155
+ vec ! [ "serde::Serialize" . to_owned( ) ]
156
+ } else {
157
+ vec ! [ ]
158
+ }
159
+ }
160
+
161
+ fn add_attributes ( & self , info : & AttributeInfo < ' _ > ) -> Vec < String > {
162
+ if info. name == & self . 0 {
163
+ vec ! [ "#[serde(transparent)]" . to_owned( ) ]
164
+ } else {
165
+ vec ! [ ]
166
+ }
167
+ }
168
+ }
169
+
149
170
pub fn lookup ( cb : & str ) -> Box < dyn ParseCallbacks > {
150
171
match cb {
151
172
"enum-variant-rename" => Box :: new ( EnumVariantRename ) ,
@@ -155,7 +176,11 @@ pub fn lookup(cb: &str) -> Box<dyn ParseCallbacks> {
155
176
"wrap-as-variadic-fn" => Box :: new ( WrapAsVariadicFn ) ,
156
177
"type-visibility" => Box :: new ( TypeVisibility ) ,
157
178
call_back => {
158
- if let Some ( prefix) =
179
+ if let Some ( name) =
180
+ call_back. strip_prefix ( "derive-transparent-serialize=" )
181
+ {
182
+ Box :: new ( DeriveTransparentSerialize ( name. to_owned ( ) ) )
183
+ } else if let Some ( prefix) =
159
184
call_back. strip_prefix ( "remove-function-prefix-" )
160
185
{
161
186
let lnopc = RemovePrefixParseCallback :: new ( prefix) ;
You can’t perform that action at this time.
0 commit comments