@@ -257,7 +257,7 @@ impl<'a> Namespace<'a> {
257257 }
258258
259259 /// Returns the supertypes of a def or an empty list if it can't be found.
260- pub fn supertypes_of ( & ' a self , symbol : & Symbol ) -> MapReadRef < Symbol , Vec < & ' a Dict > > {
260+ pub fn supertypes_of ( & ' a self , symbol : & Symbol ) -> MapReadRef < ' a , Symbol , Vec < & ' a Dict > > {
261261 if let Some ( super_types) = self . supertypes_of_cache . get ( symbol) {
262262 super_types
263263 } else {
@@ -315,8 +315,8 @@ impl<'a> Namespace<'a> {
315315
316316 /// Returns a list of choices for def.
317317 pub fn choices_for ( & self , symbol : & Symbol ) -> & Vec < Dict > {
318- if let Some ( of ) = self . get ( symbol) . and_then ( |def| def . get_symbol ( "of" ) ) {
319- self . subtypes_of ( of )
318+ if self . get ( symbol) . is_some_and ( |def| self . is_choice ( def ) ) {
319+ self . subtypes_of ( symbol )
320320 } else {
321321 & EMPTY_VEC_DICT
322322 }
@@ -326,13 +326,21 @@ impl<'a> Namespace<'a> {
326326 /// all defs that are choices.
327327 fn compute_choices ( & mut self ) {
328328 for ( sym, def) in & self . defs {
329- if def. get_symbol ( "of" ) . is_some ( ) {
329+ // A choice extends directly from 'choice'.
330+ if self . is_choice ( def) {
330331 self . choices
331332 . insert ( sym. clone ( ) , self . choices_for ( sym) . clone ( ) ) ;
332333 }
333334 }
334335 }
335336
337+ fn is_choice ( & self , def : & Dict ) -> bool {
338+ def. get_list ( "is" )
339+ . into_iter ( )
340+ . flatten ( )
341+ . any ( |v| v == & Value :: make_symbol ( "choice" ) )
342+ }
343+
336344 /// Compute a list of the features names.
337345 fn compute_feature_names ( & mut self ) {
338346 let mut features = HashSet :: < & str > :: new ( ) ;
@@ -386,7 +394,7 @@ impl<'a> Namespace<'a> {
386394 }
387395
388396 /// Return the defs inheritance as a flattened array of defs.
389- pub fn inheritance ( & ' a self , symbol : & Symbol ) -> MapReadRef < Symbol , Vec < & ' a Dict > > {
397+ pub fn inheritance ( & ' a self , symbol : & Symbol ) -> MapReadRef < ' a , Symbol , Vec < & ' a Dict > > {
390398 if let Some ( inheritance) = self . inheritance_of_cache . get ( symbol) {
391399 inheritance
392400 } else {
@@ -410,7 +418,7 @@ impl<'a> Namespace<'a> {
410418 /// - parent The parent def.
411419 /// - association The association.
412420 ///
413- pub fn associations ( & ' a self , parent : & Symbol , association : & Symbol ) -> Vec < & Dict > {
421+ pub fn associations ( & ' a self , parent : & Symbol , association : & Symbol ) -> Vec < & ' a Dict > {
414422 if let Some ( association_def) = self . get ( association) {
415423 // Make sure the association exists and is an association.
416424 if matches ! (
@@ -424,7 +432,7 @@ impl<'a> Namespace<'a> {
424432
425433 // If the association isn't computed then just get the associated defs.
426434 // For instance, this will return here if the association is 'tagOn'.
427- if !association_def. has ( "computed " ) {
435+ if !association_def. has ( "computedFromReciprocal " ) {
428436 return self
429437 . get ( parent)
430438 . and_then ( |def| def. get_list ( & association. value ) )
@@ -457,7 +465,7 @@ impl<'a> Namespace<'a> {
457465 & ' a self ,
458466 parent : & Symbol ,
459467 reciprocal_of : & Symbol ,
460- ) -> Vec < & Dict > {
468+ ) -> Vec < & ' a Dict > {
461469 let inheritance = self . inheritance ( parent) ;
462470
463471 let mut matches = HashSet :: < & Dict > :: new ( ) ;
@@ -484,7 +492,7 @@ impl<'a> Namespace<'a> {
484492 /// - parent The parent def
485493 /// # Return
486494 /// The `is` association defs
487- pub fn is ( & ' a self , parent : & Symbol ) -> Vec < & Dict > {
495+ pub fn is ( & ' a self , parent : & Symbol ) -> Vec < & ' a Dict > {
488496 self . associations ( parent, & Symbol :: from ( "is" ) )
489497 }
490498
@@ -493,7 +501,7 @@ impl<'a> Namespace<'a> {
493501 /// - parent The parent def
494502 /// # Return
495503 /// The `tagOn` association defs
496- pub fn tag_on ( & ' a self , parent : & Symbol ) -> Vec < & Dict > {
504+ pub fn tag_on ( & ' a self , parent : & Symbol ) -> Vec < & ' a Dict > {
497505 self . associations ( parent, & Symbol :: from ( "tagOn" ) )
498506 }
499507
@@ -502,7 +510,7 @@ impl<'a> Namespace<'a> {
502510 /// - parent The parent def
503511 /// # Return
504512 /// The `tags` association defs
505- pub fn tags ( & ' a self , parent : & Symbol ) -> Vec < & Dict > {
513+ pub fn tags ( & ' a self , parent : & Symbol ) -> Vec < & ' a Dict > {
506514 self . associations ( parent, & Symbol :: from ( "tags" ) )
507515 }
508516
@@ -511,7 +519,7 @@ impl<'a> Namespace<'a> {
511519 /// - subject The subject to reflect
512520 /// # Return
513521 /// The reflected defs
514- pub fn reflect ( & ' a self , subject : & Dict ) -> Reflection {
522+ pub fn reflect < ' b > ( & ' a self , subject : & ' b Dict ) -> Reflection < ' a > {
515523 let mut defs = Vec :: < & Dict > :: new ( ) ;
516524 let mut markers = HashSet :: < & str > :: new ( ) ;
517525
@@ -698,11 +706,10 @@ impl<'a> Namespace<'a> {
698706 pub fn protos ( & ' a self , parent : & Dict ) -> Vec < Dict > {
699707 parent
700708 . keys ( )
701- . map ( |name| self . protos_from_def ( parent, name) )
702- . fold ( Vec :: new ( ) , |mut vec, cur| {
703- vec. extend ( cur) ;
704- vec
705- } )
709+ . flat_map ( |name| self . protos_from_def ( parent, name) )
710+ . collect :: < HashSet < _ > > ( )
711+ . into_iter ( )
712+ . collect ( )
706713 }
707714
708715 /// Return a reflected list of children prototypes for the parent dict.
0 commit comments