diff options
author | Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> | 2022-11-02 13:46:22 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 13:46:22 -0500 |
commit | a673a6bc9b83675a7468379e79dcf5d5659c4623 (patch) | |
tree | 5bf1b4d228bd8ff451d790c85cf4033e49cd9ff2 /bindgen/codegen/mod.rs | |
parent | 83426897af20d938fb4dca879d54de456ab96d6b (diff) |
Allow callback composition (#2330)
* Allow callback composition
Store all the callbacks added to the builder in a `Vec` so bindgen
invokes each one of them in a last-to-first manner.
Diffstat (limited to 'bindgen/codegen/mod.rs')
-rw-r--r-- | bindgen/codegen/mod.rs | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index bf0b3356..a59265ab 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2112,12 +2112,11 @@ impl CodeGenerator for CompInfo { // The custom derives callback may return a list of derive attributes; // add them to the end of the list. - let custom_derives; - if let Some(cb) = &ctx.options().parse_callbacks { - custom_derives = cb.add_derives(&canonical_name); - // In most cases this will be a no-op, since custom_derives will be empty. - derives.extend(custom_derives.iter().map(|s| s.as_str())); - }; + let custom_derives = ctx + .options() + .all_callbacks(|cb| cb.add_derives(&canonical_name)); + // In most cases this will be a no-op, since custom_derives will be empty. + derives.extend(custom_derives.iter().map(|s| s.as_str())); if !derives.is_empty() { attributes.push(attributes::derives(&derives)) @@ -3152,12 +3151,10 @@ impl CodeGenerator for Enum { // The custom derives callback may return a list of derive attributes; // add them to the end of the list. - let custom_derives; - if let Some(cb) = &ctx.options().parse_callbacks { - custom_derives = cb.add_derives(&name); - // In most cases this will be a no-op, since custom_derives will be empty. - derives.extend(custom_derives.iter().map(|s| s.as_str())); - }; + let custom_derives = + ctx.options().all_callbacks(|cb| cb.add_derives(&name)); + // In most cases this will be a no-op, since custom_derives will be empty. + derives.extend(custom_derives.iter().map(|s| s.as_str())); attrs.push(attributes::derives(&derives)); } |