summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md3
-rw-r--r--bindgen-integration/build.rs10
-rw-r--r--bindgen/callbacks.rs10
-rw-r--r--bindgen/codegen/mod.rs13
4 files changed, 26 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 237e3801..9224c018 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -155,6 +155,9 @@
## Changed
+ * Replace the `name: &str` argument for `ParseCallbacks::add_derives` by
+ `info: DeriveInfo`.
+
## Removed
* The following deprecated methods and their equivalent CLI arguments were
diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs
index 980d40b9..0f30ad47 100644
--- a/bindgen-integration/build.rs
+++ b/bindgen-integration/build.rs
@@ -1,7 +1,9 @@
extern crate bindgen;
extern crate cc;
-use bindgen::callbacks::{IntKind, MacroParsingBehavior, ParseCallbacks};
+use bindgen::callbacks::{
+ DeriveInfo, IntKind, MacroParsingBehavior, ParseCallbacks,
+};
use bindgen::{Builder, EnumVariation};
use std::collections::HashSet;
use std::env;
@@ -121,10 +123,10 @@ impl ParseCallbacks for MacroCallback {
}
// Test the "custom derives" capability by adding `PartialEq` to the `Test` struct.
- fn add_derives(&self, name: &str) -> Vec<String> {
- if name == "Test" {
+ fn add_derives(&self, info: &DeriveInfo<'_>) -> Vec<String> {
+ if info.name == "Test" {
vec!["PartialEq".into()]
- } else if name == "MyOrderedEnum" {
+ } else if info.name == "MyOrderedEnum" {
vec!["std::cmp::PartialOrd".into()]
} else {
vec![]
diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs
index fb84c8c3..bebd6978 100644
--- a/bindgen/callbacks.rs
+++ b/bindgen/callbacks.rs
@@ -105,7 +105,15 @@ pub trait ParseCallbacks: fmt::Debug {
///
/// If no additional attributes are wanted, this function should return an
/// empty `Vec`.
- fn add_derives(&self, _name: &str) -> Vec<String> {
+ fn add_derives(&self, _info: &DeriveInfo<'_>) -> Vec<String> {
vec![]
}
}
+
+/// Relevant information about a type to which new derive attributes will be added using
+/// [`ParseCallbacks::add_derives`].
+#[non_exhaustive]
+pub struct DeriveInfo<'a> {
+ /// The name of the type.
+ pub name: &'a str,
+}
diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs
index c7ac59db..e758963a 100644
--- a/bindgen/codegen/mod.rs
+++ b/bindgen/codegen/mod.rs
@@ -2114,9 +2114,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 = ctx
- .options()
- .all_callbacks(|cb| cb.add_derives(&canonical_name));
+ let custom_derives = ctx.options().all_callbacks(|cb| {
+ cb.add_derives(&crate::callbacks::DeriveInfo {
+ name: &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()));
@@ -3168,8 +3170,9 @@ 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 =
- ctx.options().all_callbacks(|cb| cb.add_derives(&name));
+ let custom_derives = ctx.options().all_callbacks(|cb| {
+ cb.add_derives(&crate::callbacks::DeriveInfo { name: &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()));