@@ -186,53 +186,62 @@ pub fn load_crate(cache_path: &str, name: &str) -> PyResult<Option<Crate>> {
186186
187187#[ pyfunction]
188188/// 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 > > {
190190 let path = std:: path:: Path :: new ( cache_path)
191191 . join ( "modules" )
192- . join ( format ! ( "{}.json" , name ) ) ;
192+ . join ( format ! ( "{}.json" , full_name ) ) ;
193193 if !path. exists ( ) {
194194 return Ok ( None ) ;
195195 }
196196 let contents = read_file ( & path) ?;
197- let mod_: analyze:: Module = deserialize_object ( name , & contents) ?;
197+ let mod_: analyze:: Module = deserialize_object ( full_name , & contents) ?;
198198 Ok ( Some ( mod_. into ( ) ) )
199199}
200200
201201#[ pyfunction]
202202/// 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 > > {
204204 let path = std:: path:: Path :: new ( cache_path)
205205 . join ( "structs" )
206- . join ( format ! ( "{}.json" , name ) ) ;
206+ . join ( format ! ( "{}.json" , full_name ) ) ;
207207 if !path. exists ( ) {
208208 return Ok ( None ) ;
209209 }
210210 let contents = read_file ( & path) ?;
211- let struct_: analyze:: Struct = deserialize_object ( name , & contents) ?;
211+ let struct_: analyze:: Struct = deserialize_object ( full_name , & contents) ?;
212212 Ok ( Some ( struct_. into ( ) ) )
213213}
214214
215215#[ pyfunction]
216216/// 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 > > {
218218 let path = std:: path:: Path :: new ( cache_path)
219219 . join ( "enums" )
220- . join ( format ! ( "{}.json" , name ) ) ;
220+ . join ( format ! ( "{}.json" , full_name ) ) ;
221221 if !path. exists ( ) {
222222 return Ok ( None ) ;
223223 }
224224 let contents = read_file ( & path) ?;
225- let enum_: analyze:: Enum = deserialize_object ( name , & contents) ?;
225+ let enum_: analyze:: Enum = deserialize_object ( full_name , & contents) ?;
226226 Ok ( Some ( enum_. into ( ) ) )
227227}
228228
229229#[ 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 > > {
232236 let path = std:: path:: Path :: new ( cache_path) . join ( "modules" ) ;
233237 if !path. exists ( ) {
234238 return Ok ( vec ! [ ] ) ;
235239 }
240+ let ancestor_name = ancestor. join ( "::" ) ;
241+ let mut prefix = ancestor. join ( "::" ) ;
242+ if !prefix. is_empty ( ) {
243+ prefix. push_str ( "::" ) ;
244+ }
236245 let mut modules = vec ! [ ] ;
237246 for entry in std:: fs:: read_dir ( path) ? {
238247 let entry = entry?;
@@ -246,7 +255,7 @@ pub fn load_modules(cache_path: &str, prefix: &str) -> PyResult<Vec<Module>> {
246255 Some ( name) => name,
247256 None => continue ,
248257 } ;
249- if !name. starts_with ( prefix) {
258+ if !( name. starts_with ( & prefix) || ( include_self && name == & ancestor_name ) ) {
250259 continue ;
251260 }
252261 let contents = read_file ( & path) ?;
@@ -258,12 +267,16 @@ pub fn load_modules(cache_path: &str, prefix: &str) -> PyResult<Vec<Module>> {
258267}
259268
260269#[ 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 > > {
263272 let path = std:: path:: Path :: new ( cache_path) . join ( "structs" ) ;
264273 if !path. exists ( ) {
265274 return Ok ( vec ! [ ] ) ;
266275 }
276+ let mut prefix = ancestor. join ( "::" ) ;
277+ if !prefix. is_empty ( ) {
278+ prefix. push_str ( "::" ) ;
279+ }
267280 let mut structs = vec ! [ ] ;
268281 for entry in std:: fs:: read_dir ( path) ? {
269282 let entry = entry?;
@@ -277,7 +290,7 @@ pub fn load_structs(cache_path: &str, prefix: &str) -> PyResult<Vec<Struct>> {
277290 Some ( name) => name,
278291 None => continue ,
279292 } ;
280- if !name. starts_with ( prefix) {
293+ if !name. starts_with ( & prefix) {
281294 continue ;
282295 }
283296 let contents = read_file ( & path) ?;
@@ -289,12 +302,16 @@ pub fn load_structs(cache_path: &str, prefix: &str) -> PyResult<Vec<Struct>> {
289302}
290303
291304#[ 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 > > {
294307 let path = std:: path:: Path :: new ( cache_path) . join ( "enums" ) ;
295308 if !path. exists ( ) {
296309 return Ok ( vec ! [ ] ) ;
297310 }
311+ let mut prefix = ancestor. join ( "::" ) ;
312+ if !prefix. is_empty ( ) {
313+ prefix. push_str ( "::" ) ;
314+ }
298315 let mut enums = vec ! [ ] ;
299316 for entry in std:: fs:: read_dir ( path) ? {
300317 let entry = entry?;
@@ -308,7 +325,7 @@ pub fn load_enums(cache_path: &str, prefix: &str) -> PyResult<Vec<Enum>> {
308325 Some ( name) => name,
309326 None => continue ,
310327 } ;
311- if !name. starts_with ( prefix) {
328+ if !name. starts_with ( & prefix) {
312329 continue ;
313330 }
314331 let contents = read_file ( & path) ?;
0 commit comments