@@ -186,53 +186,62 @@ pub fn load_crate(cache_path: &str, name: &str) -> PyResult<Option<Crate>> {
186
186
187
187
#[ pyfunction]
188
188
/// load a module from the cache, if it exists
189
- pub fn load_module ( cache_path : & str , name : & str ) -> PyResult < Option < Module > > {
189
+ pub fn load_module ( cache_path : & str , full_name : & str ) -> PyResult < Option < Module > > {
190
190
let path = std:: path:: Path :: new ( cache_path)
191
191
. join ( "modules" )
192
- . join ( format ! ( "{}.json" , name ) ) ;
192
+ . join ( format ! ( "{}.json" , full_name ) ) ;
193
193
if !path. exists ( ) {
194
194
return Ok ( None ) ;
195
195
}
196
196
let contents = read_file ( & path) ?;
197
- let mod_: analyze:: Module = deserialize_object ( name , & contents) ?;
197
+ let mod_: analyze:: Module = deserialize_object ( full_name , & contents) ?;
198
198
Ok ( Some ( mod_. into ( ) ) )
199
199
}
200
200
201
201
#[ pyfunction]
202
202
/// load a struct from the cache, if it exists
203
- pub fn load_struct ( cache_path : & str , name : & str ) -> PyResult < Option < Struct > > {
203
+ pub fn load_struct ( cache_path : & str , full_name : & str ) -> PyResult < Option < Struct > > {
204
204
let path = std:: path:: Path :: new ( cache_path)
205
205
. join ( "structs" )
206
- . join ( format ! ( "{}.json" , name ) ) ;
206
+ . join ( format ! ( "{}.json" , full_name ) ) ;
207
207
if !path. exists ( ) {
208
208
return Ok ( None ) ;
209
209
}
210
210
let contents = read_file ( & path) ?;
211
- let struct_: analyze:: Struct = deserialize_object ( name , & contents) ?;
211
+ let struct_: analyze:: Struct = deserialize_object ( full_name , & contents) ?;
212
212
Ok ( Some ( struct_. into ( ) ) )
213
213
}
214
214
215
215
#[ pyfunction]
216
216
/// load an enum from the cache, if it exists
217
- pub fn load_enum ( cache_path : & str , name : & str ) -> PyResult < Option < Enum > > {
217
+ pub fn load_enum ( cache_path : & str , full_name : & str ) -> PyResult < Option < Enum > > {
218
218
let path = std:: path:: Path :: new ( cache_path)
219
219
. join ( "enums" )
220
- . join ( format ! ( "{}.json" , name ) ) ;
220
+ . join ( format ! ( "{}.json" , full_name ) ) ;
221
221
if !path. exists ( ) {
222
222
return Ok ( None ) ;
223
223
}
224
224
let contents = read_file ( & path) ?;
225
- let enum_: analyze:: Enum = deserialize_object ( name , & contents) ?;
225
+ let enum_: analyze:: Enum = deserialize_object ( full_name , & contents) ?;
226
226
Ok ( Some ( enum_. into ( ) ) )
227
227
}
228
228
229
229
#[ pyfunction]
230
- /// load all modules from the cache that begin with the given prefix
231
- pub fn load_modules ( cache_path : & str , prefix : & str ) -> PyResult < Vec < Module > > {
230
+ /// load all modules from the cache that have a common ancestor
231
+ pub fn load_modules (
232
+ cache_path : & str ,
233
+ ancestor : Vec < String > ,
234
+ include_self : bool ,
235
+ ) -> PyResult < Vec < Module > > {
232
236
let path = std:: path:: Path :: new ( cache_path) . join ( "modules" ) ;
233
237
if !path. exists ( ) {
234
238
return Ok ( vec ! [ ] ) ;
235
239
}
240
+ let ancestor_name = ancestor. join ( "::" ) ;
241
+ let mut prefix = ancestor. join ( "::" ) ;
242
+ if !prefix. is_empty ( ) {
243
+ prefix. push_str ( "::" ) ;
244
+ }
236
245
let mut modules = vec ! [ ] ;
237
246
for entry in std:: fs:: read_dir ( path) ? {
238
247
let entry = entry?;
@@ -246,7 +255,7 @@ pub fn load_modules(cache_path: &str, prefix: &str) -> PyResult<Vec<Module>> {
246
255
Some ( name) => name,
247
256
None => continue ,
248
257
} ;
249
- if !name. starts_with ( prefix) {
258
+ if !( name. starts_with ( & prefix) || ( include_self && name == & ancestor_name ) ) {
250
259
continue ;
251
260
}
252
261
let contents = read_file ( & path) ?;
@@ -258,12 +267,16 @@ pub fn load_modules(cache_path: &str, prefix: &str) -> PyResult<Vec<Module>> {
258
267
}
259
268
260
269
#[ pyfunction]
261
- /// load all structs from the cache that begin with the given prefix
262
- pub fn load_structs ( cache_path : & str , prefix : & str ) -> PyResult < Vec < Struct > > {
270
+ /// load all structs from the cache that have a common ancestor
271
+ pub fn load_structs ( cache_path : & str , ancestor : Vec < String > ) -> PyResult < Vec < Struct > > {
263
272
let path = std:: path:: Path :: new ( cache_path) . join ( "structs" ) ;
264
273
if !path. exists ( ) {
265
274
return Ok ( vec ! [ ] ) ;
266
275
}
276
+ let mut prefix = ancestor. join ( "::" ) ;
277
+ if !prefix. is_empty ( ) {
278
+ prefix. push_str ( "::" ) ;
279
+ }
267
280
let mut structs = vec ! [ ] ;
268
281
for entry in std:: fs:: read_dir ( path) ? {
269
282
let entry = entry?;
@@ -277,7 +290,7 @@ pub fn load_structs(cache_path: &str, prefix: &str) -> PyResult<Vec<Struct>> {
277
290
Some ( name) => name,
278
291
None => continue ,
279
292
} ;
280
- if !name. starts_with ( prefix) {
293
+ if !name. starts_with ( & prefix) {
281
294
continue ;
282
295
}
283
296
let contents = read_file ( & path) ?;
@@ -289,12 +302,16 @@ pub fn load_structs(cache_path: &str, prefix: &str) -> PyResult<Vec<Struct>> {
289
302
}
290
303
291
304
#[ pyfunction]
292
- /// load all enums from the cache that begin with the given prefix
293
- pub fn load_enums ( cache_path : & str , prefix : & str ) -> PyResult < Vec < Enum > > {
305
+ /// load all enums from the cache that that have a common ancestor
306
+ pub fn load_enums ( cache_path : & str , ancestor : Vec < String > ) -> PyResult < Vec < Enum > > {
294
307
let path = std:: path:: Path :: new ( cache_path) . join ( "enums" ) ;
295
308
if !path. exists ( ) {
296
309
return Ok ( vec ! [ ] ) ;
297
310
}
311
+ let mut prefix = ancestor. join ( "::" ) ;
312
+ if !prefix. is_empty ( ) {
313
+ prefix. push_str ( "::" ) ;
314
+ }
298
315
let mut enums = vec ! [ ] ;
299
316
for entry in std:: fs:: read_dir ( path) ? {
300
317
let entry = entry?;
@@ -308,7 +325,7 @@ pub fn load_enums(cache_path: &str, prefix: &str) -> PyResult<Vec<Enum>> {
308
325
Some ( name) => name,
309
326
None => continue ,
310
327
} ;
311
- if !name. starts_with ( prefix) {
328
+ if !name. starts_with ( & prefix) {
312
329
continue ;
313
330
}
314
331
let contents = read_file ( & path) ?;
0 commit comments