summaryrefslogtreecommitdiff
path: root/bindgen/callbacks.rs
diff options
context:
space:
mode:
authorJustin W Smith <103147162+justsmth@users.noreply.github.com>2022-11-28 13:16:10 -0500
committerGitHub <noreply@github.com>2022-11-28 13:16:10 -0500
commit199dfcc8e598ba834f7a7210a6ce004e99499d4f (patch)
tree31552506c986ea6a36e8f55b848d76789ff33b99 /bindgen/callbacks.rs
parent690feb398bb5d56eeb928124291663c71f8af054 (diff)
Extend `generated_name_override` callback to variables (#2351)
* This change updates `ParseCallbacks::generated_name_override` to accept a second parameter indicating the kind of item the name applies to (currently, either `Function` or `Var`). * A `CallbackItemKind` enum was added to serve as the type for this second parameter. * Tests have been updated to verify that the names of both function and variable can be updated by this callback.
Diffstat (limited to 'bindgen/callbacks.rs')
-rw-r--r--bindgen/callbacks.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs
index 5e8ac788..1e48a302 100644
--- a/bindgen/callbacks.rs
+++ b/bindgen/callbacks.rs
@@ -30,9 +30,9 @@ pub trait ParseCallbacks: fmt::Debug {
MacroParsingBehavior::Default
}
- /// This function will run for every function. The returned value determines the name visible
- /// in the bindings.
- fn generated_name_override(&self, _function_name: &str) -> Option<String> {
+ /// This function will run for every extern variable and function. The returned value determines
+ /// the name visible in the bindings.
+ fn generated_name_override(&self, _item_info: ItemInfo) -> Option<String> {
None
}
@@ -122,3 +122,21 @@ pub struct DeriveInfo<'a> {
/// The name of the type.
pub name: &'a str,
}
+
+/// An struct providing information about the item being passed to `ParseCallbacks::generated_name_override`.
+#[non_exhaustive]
+pub struct ItemInfo<'a> {
+ /// The name of the item
+ pub name: &'a str,
+ /// The kind of item
+ pub kind: ItemKind,
+}
+
+/// An enum indicating the kind of item for an ItemInfo.
+#[non_exhaustive]
+pub enum ItemKind {
+ /// A Function
+ Function,
+ /// A Variable
+ Var,
+}