-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Associated types not resolved to concrete type #1924
Comments
I am looking into solving this. Here is my plan. I would appreciate any guidance: since this is my first potential TL;DR: we generate a new
pub trait __bindgen_has_associated_type_ASSOCIATED_TYPE_NAME {
type ASSOCIATED_TYPE_NAME;
}; (generated only once per impl __bindgen_has_associated_type_ASSOCIATED_TYPE_NAME for TYPE {
type ASSOCIATED_TYPE_NAME = WHATEVER_THE_TYPEDEF_POINTED_TO;
}
I anticipate Much Doom in attempting to implement this plan. Any pointers for how to avoid the most egregious pits of lava would be much appreciated. |
OK, here's my progress so far (this is a branch 90% full of logging hacks, obviously much rebasing and cleaning would occur before PRing it). A few differences from the above plan:
template <typename ContainedType> class Container {
public:
typedef typename ContainedType::related_type content_ty;
...
} the pub type Container_content_ty = ContainedType::related_type instead of pub type Container_content_ty<ContainedType> = ContainedType::related_type Once I can make those edges appear properly, there's further work even on this specific line because it actually needs to be pub type Container_content_ty<ContainedType> = <ContainedType as __bindgen_has_inner_type_related_type>::related_type; but that's for later. |
OK, I came back to this after a while and found I couldn't remember much :) Notes-to-self: How to run & test
What worksI have managed to make a suitable edge exist to the struct InnerType {
typedef int related_type;
long int foo;
};
template <typename ContainedType> class Container {
public:
typename ContainedType::related_type contents_;
};
typedef Container<InnerType> Concrete; we now generate the following bindings (test code removed for clarity): #[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct InnerType {
pub foo: ::std::os::raw::c_long,
}
pub type InnerType_related_type = ::std::os::raw::c_int;
pub trait __bindgen_has_inner_type_related_type {
type related_type: std::fmt::Debug + Copy + Clone + Default;
}
impl __bindgen_has_inner_type_related_type for InnerType {
type related_type = InnerType_related_type;
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Container<ContainedType: __bindgen_has_inner_type_related_type> {
pub contents_: ContainedType::related_type,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<ContainedType>>,
}
pub type Concrete = Container; What doesn't workThis is all correct except:
Next stepsI'm hoping to:
|
Input C/C++ Header
Bindgen Invocation
Rust code
Actual Results
Expected Results
I'd expect the type of
contents_
to be ac_int
.Other notes
Perhaps this counts as the "traits templates" situation listed under the recorded C++ limitations but, as it doesn't involve any nasty SFINAE magic I am hoping this may be possible.
Thanks for bindgen, it's amazing! Apologies if this is a duplicate.
The text was updated successfully, but these errors were encountered: