-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For a situation like this: struct InnerType { typedef int related_type; int foo; int foo2; }; template <typename ContainedType> class Container { public: typedef typename ContainedType::related_type content_ty; content_ty contents_; }; typedef Container<InnerType> Concrete; struct LaterContainingType { Concrete outer_contents; }; previously bindgen would have generated an opaque type. It now correctly recognizes that the contents_ field is of a new TypeKind::DependentQualifiedName and correctly identifies the right type to use when instantiating Concrete. The generated code looks like this: #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct InnerType { pub foo: ::std::os::raw::c_int, pub foo2: ::std::os::raw::c_int, } pub type InnerType_related_type = ::std::os::raw::c_int; pub trait __bindgen_has_inner_type_related_type { type related_type: std::fmt::Debug + Default + Copy + Clone; } 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_: Container_content_ty<ContainedType>, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<ContainedType>>, } pub type Container_content_ty<ContainedType> = <ContainedType as __bindgen_has_inner_type_related_type>::related_type; pub type Concrete = Container<InnerType>; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct LaterContainingType { pub outer_contents: Concrete, } Note the trait constructed to mark types which have an inner type. This trait is then used in the Rust definition of Container_content_ty. Such a trait is emitted only if it's actually used, to avoid too much verbosity. This is useful for types which are parameterized with a traits type. For example Chromium's base::StringPiece which is parameterized by an STL string type (e.g. std::string) and looks up the correct size of character to use by using a parameterized type: typedef typename STRING_TYPE::value_type value_type; (Of course, std::string and other string types have other reasons why they're difficult to work with from Rust, such as self-referential pointers, but that's another story). This change assumes all types involved derive the same traits: in the above example note that __bindgen_has_inner_type_related_type requires all traits be derived. It would be possible to be more nuanced here and move those trait bounds to the places where the trait is used (e.g. pub type Concrete = ... in the above example).
- Loading branch information
Showing
16 changed files
with
559 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.