/// A trait for the things which we can codegen tokens that contribute towards a /// generated `impl Debug`. pub(crate) trait ImplDebug<'a> { /// Any extra parameter required by this a particular `ImplDebug` implementation. type Extra;
/// Generate a format string snippet to be included in the larger `impl Debug` /// format string, and the code to get the format string's interpolation values. fn impl_debug(
&self,
ctx: &BindgenContext,
extra: Self::Extra,
) -> Option<(String, Vec<proc_macro2::TokenStream>)>;
}
impl<'a> ImplDebug<'a> for FieldData { type Extra = ();
// We don't know if blocklisted items `impl Debug` or not, so we can't // add them to the format string we're building up. if !ctx.allowlisted_items().contains(&self.id()) { return None;
}
let ty = matchself.as_type() {
Some(ty) => ty,
None => { return None;
}
};
// The generic is not required to implement Debug, so we can not debug print that type
TypeKind::TypeParam => {
Some((format!("{}: Non-debuggable generic", name), vec![]))
}
TypeKind::Array(_, len) => { // Generics are not required to implement Debug ifself.has_type_param_in_array(ctx) {
Some((
format!("{}: Array with length {}", name, len),
vec![],
))
} elseif len < RUST_DERIVE_IN_ARRAY_LIMIT ||
ctx.options().rust_features().larger_arrays
{ // The simple case
debug_print(name, quote! { #name_ident })
} elseif ctx.options().use_core { // There is no String in core; reducing field visibility to avoid breaking // no_std setups.
Some((format!("{}: [...]", name), vec![]))
} else { // Let's implement our own print function
Some((
format!("{}: [{{}}]", name),
vec![quote! { self.#name_ident
.iter()
.enumerate()
.map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v))
.collect::<String>()
}],
))
}
}
TypeKind::Vector(_, len) => { if ctx.options().use_core { // There is no format! in core; reducing field visibility to avoid breaking // no_std setups.
Some((format!("{}(...)", name), vec![]))
} else { let self_ids = 0..len;
Some((
format!("{}({{}})", name),
vec![quote! { #(format!("{:?}", self.#self_ids)),*
}],
))
}
}
TypeKind::ResolvedTypeRef(t) |
TypeKind::TemplateAlias(t, _) |
TypeKind::Alias(t) |
TypeKind::BlockPointer(t) => { // We follow the aliases
ctx.resolve_item(t).impl_debug(ctx, name)
}
TypeKind::Pointer(inner) => { let inner_type = ctx.resolve_type(inner).canonical_type(ctx); match *inner_type.kind() {
TypeKind::Function(ref sig) if !sig.function_pointers_can_derive() =>
{
Some((format!("{}: FunctionPointer", name), vec![]))
}
_ => debug_print(name, quote! { #name_ident }),
}
}
TypeKind::Opaque => None,
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-06-19)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.