Take this example C++ code:
#pragma once
template <typename Type> class Vector2 {
Type x;
Type y;
};
template <typename Type> class Rectangle {
public:
using Vector2Type = Vector2<Type>;
Vector2Type p0;
Vector2Type p1;
};
using Vector2f = Vector2<float>;
using Rectanglef = Rectangle<float>;
The bindings generated by bindgen when allowlist_recursively is false are:
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Vector2<Type> {
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<Type>>,
x: Type,
y: Type,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Rectangle<Type> {
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<Type>>,
pub p0: Rectangle_Vector2Type,
pub p1: Rectangle_Vector2Type,
}
pub type Rectangle_Vector2Type = Vector2<Type>;
pub type Vector2f = Vector2<f32>;
pub type Rectanglef = Rectangle<f32>;
The generic type from Rectangle_Vector2Type has been dropped and the code is no longer valid. Setting allowlist_recursively to true will generate the correct code:
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Rectangle<Type> {
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<Type>>,
pub p0: Rectangle_Vector2Type<Type>,
pub p1: Rectangle_Vector2Type<Type>,
}
pub type Rectangle_Vector2Type<Type> = Vector2<Type>;
Adding in more allowlist types, like Vector2Type or Rectangle::Vector2Type still does not prevent the generic from being generated correctly.
Bindgen version: 0.72.1
Take this example C++ code:
The bindings generated by bindgen when
allowlist_recursivelyis false are:The generic type from
Rectangle_Vector2Typehas been dropped and the code is no longer valid. Settingallowlist_recursivelyto true will generate the correct code:Adding in more allowlist types, like
Vector2TypeorRectangle::Vector2Typestill does not prevent the generic from being generated correctly.Bindgen version: 0.72.1