Trait bindgen::callbacks::ParseCallbacks
source · pub trait ParseCallbacks: Debug {
// Provided methods
fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior { ... }
fn generated_name_override(&self, _function_name: &str) -> Option<String> { ... }
fn int_macro(&self, _name: &str, _value: i64) -> Option<IntKind> { ... }
fn str_macro(&self, _name: &str, _value: &[u8]) { ... }
fn func_macro(&self, _name: &str, _value: &[&[u8]]) { ... }
fn enum_variant_behavior(
&self,
_enum_name: Option<&str>,
_original_variant_name: &str,
_variant_value: EnumVariantValue,
) -> Option<EnumVariantCustomBehavior> { ... }
fn enum_variant_name(
&self,
_enum_name: Option<&str>,
_original_variant_name: &str,
_variant_value: EnumVariantValue,
) -> Option<String> { ... }
fn item_name(&self, _original_item_name: &str) -> Option<String> { ... }
fn include_file(&self, _filename: &str) { ... }
fn blocklisted_type_implements_trait(
&self,
_name: &str,
_derive_trait: DeriveTrait,
) -> Option<ImplementsTrait> { ... }
fn add_derives(&self, _info: &DeriveInfo<'_>) -> Vec<String> { ... }
fn process_comment(&self, _comment: &str) -> Option<String> { ... }
}
Expand description
A trait to allow configuring different kinds of types in different situations.
Provided Methods§
sourcefn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior
fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior
This function will be run on every macro that is identified.
sourcefn generated_name_override(&self, _function_name: &str) -> Option<String>
fn generated_name_override(&self, _function_name: &str) -> Option<String>
This function will run for every function. The returned value determines the name visible in the bindings.
sourcefn int_macro(&self, _name: &str, _value: i64) -> Option<IntKind>
fn int_macro(&self, _name: &str, _value: i64) -> Option<IntKind>
The integer kind an integer macro should have, given a name and the
value of that macro, or None
if you want the default to be chosen.
sourcefn str_macro(&self, _name: &str, _value: &[u8])
fn str_macro(&self, _name: &str, _value: &[u8])
This will be run on every string macro. The callback cannot influence the further treatment of the macro, but may use the value to generate additional code or configuration.
sourcefn func_macro(&self, _name: &str, _value: &[&[u8]])
fn func_macro(&self, _name: &str, _value: &[&[u8]])
This will be run on every function-like macro. The callback cannot influence the further treatment of the macro, but may use the value to generate additional code or configuration.
The first parameter represents the name and argument list (including the parentheses) of the function-like macro. The second parameter represents the expansion of the macro as a sequence of tokens.
sourcefn enum_variant_behavior(
&self,
_enum_name: Option<&str>,
_original_variant_name: &str,
_variant_value: EnumVariantValue,
) -> Option<EnumVariantCustomBehavior>
fn enum_variant_behavior( &self, _enum_name: Option<&str>, _original_variant_name: &str, _variant_value: EnumVariantValue, ) -> Option<EnumVariantCustomBehavior>
This function should return whether, given an enum variant name, and value, this enum variant will forcibly be a constant.
sourcefn enum_variant_name(
&self,
_enum_name: Option<&str>,
_original_variant_name: &str,
_variant_value: EnumVariantValue,
) -> Option<String>
fn enum_variant_name( &self, _enum_name: Option<&str>, _original_variant_name: &str, _variant_value: EnumVariantValue, ) -> Option<String>
Allows to rename an enum variant, replacing _original_variant_name
.
sourcefn item_name(&self, _original_item_name: &str) -> Option<String>
fn item_name(&self, _original_item_name: &str) -> Option<String>
Allows to rename an item, replacing _original_item_name
.
sourcefn include_file(&self, _filename: &str)
fn include_file(&self, _filename: &str)
This will be called on every file inclusion, with the full path of the included file.
sourcefn blocklisted_type_implements_trait(
&self,
_name: &str,
_derive_trait: DeriveTrait,
) -> Option<ImplementsTrait>
fn blocklisted_type_implements_trait( &self, _name: &str, _derive_trait: DeriveTrait, ) -> Option<ImplementsTrait>
This will be called to determine whether a particular blocklisted type implements a trait or not. This will be used to implement traits on other types containing the blocklisted type.
None
: use the default behaviorSome(ImplementsTrait::Yes)
:_name
implements_derive_trait
Some(ImplementsTrait::Manually)
: any type including_name
can’t derive_derive_trait
but can implemented it manuallySome(ImplementsTrait::No)
:_name
doesn’t implement_derive_trait
sourcefn add_derives(&self, _info: &DeriveInfo<'_>) -> Vec<String>
fn add_derives(&self, _info: &DeriveInfo<'_>) -> Vec<String>
Provide a list of custom derive attributes.
If no additional attributes are wanted, this function should return an
empty Vec
.
sourcefn process_comment(&self, _comment: &str) -> Option<String>
fn process_comment(&self, _comment: &str) -> Option<String>
Process a source code comment.