@@ -162,6 +162,62 @@ pub trait ParseCallbacks: fmt::Debug {
162
162
fn wrap_as_variadic_fn ( & self , _name : & str ) -> Option < String > {
163
163
None
164
164
}
165
+
166
+ /// This will get called everytime an item (currently struct, union, and alias) is found with some information about it
167
+ fn new_item_found ( & self , _id : DiscoveredItemId , _item : DiscoveredItem ) { }
168
+
169
+ // TODO add callback for ResolvedTypeRef
170
+ }
171
+
172
+ /// An identifier for a discovered item. Used to identify an aliased type (see [DiscoveredItem::Alias])
173
+ #[ derive( Ord , PartialOrd , PartialEq , Eq , Hash , Debug , Clone , Copy ) ]
174
+ pub struct DiscoveredItemId ( usize ) ;
175
+
176
+ impl DiscoveredItemId {
177
+ /// Constructor
178
+ pub fn new ( value : usize ) -> Self {
179
+ Self ( value)
180
+ }
181
+ }
182
+
183
+ /// Struct passed to [ParseCallbacks::new_item_found] containing information about discovered
184
+ /// items (struct, union, and alias)
185
+ #[ derive( Debug , Hash , Clone , Ord , PartialOrd , Eq , PartialEq ) ]
186
+ pub enum DiscoveredItem {
187
+ /// Represents a struct with its original name in C and its generated binding name
188
+ Struct {
189
+ /// The original name (learnt from C) of the structure
190
+ /// Can be None if the union is anonymous.
191
+ original_name : Option < String > ,
192
+
193
+ /// The name of the generated binding
194
+ final_name : String ,
195
+ } ,
196
+
197
+ /// Represents a union with its original name in C and its generated binding name
198
+ Union {
199
+ /// The original name (learnt from C) of the structure.
200
+ /// Can be None if the union is anonymous.
201
+ original_name : Option < String > ,
202
+
203
+ /// The name of the generated binding
204
+ final_name : String ,
205
+ } ,
206
+
207
+ /// Represents an alias like a typedef
208
+ /// ```c
209
+ /// typedef struct MyStruct {
210
+ /// ...
211
+ /// } StructAlias;
212
+ /// ```
213
+ /// Here, the name of the alias is `StructAlias` and it's an alias for `MyStruct`
214
+ Alias {
215
+ /// The name of the alias in C (`StructAlias`)
216
+ alias_name : String ,
217
+
218
+ /// The identifier of the discovered type
219
+ alias_for : DiscoveredItemId ,
220
+ } , // functions, modules, etc.
165
221
}
166
222
167
223
/// Relevant information about a type to which new derive attributes will be added using
0 commit comments