@@ -58,7 +58,7 @@ pub struct Entities {
58
58
/// Important internal invariant: for any `Entities` object that exists, the
59
59
/// the `ancestor` relation is transitively closed.
60
60
#[ serde_as( as = "Vec<(_, _)>" ) ]
61
- entities : HashMap < EntityUID , Entity > ,
61
+ entities : HashMap < EntityUID , Arc < Entity > > ,
62
62
63
63
/// The mode flag determines whether this store functions as a partial store or
64
64
/// as a fully concrete store.
@@ -109,7 +109,7 @@ impl Entities {
109
109
110
110
/// Iterate over the `Entity`s in the `Entities`
111
111
pub fn iter ( & self ) -> impl Iterator < Item = & Entity > {
112
- self . entities . values ( )
112
+ self . entities . values ( ) . map ( |e| e . as_ref ( ) )
113
113
}
114
114
115
115
/// Adds the [`crate::ast::Entity`]s in the iterator to this [`Entities`].
@@ -140,7 +140,7 @@ impl Entities {
140
140
return Err ( EntitiesError :: duplicate ( entity. uid ( ) . clone ( ) ) )
141
141
}
142
142
hash_map:: Entry :: Vacant ( vacant_entry) => {
143
- vacant_entry. insert ( entity) ;
143
+ vacant_entry. insert ( Arc :: new ( entity) ) ;
144
144
}
145
145
}
146
146
}
@@ -213,7 +213,7 @@ impl Entities {
213
213
schema
214
214
. action_entities ( )
215
215
. into_iter ( )
216
- . map ( |e| ( e. uid ( ) . clone ( ) , Arc :: unwrap_or_clone ( e ) ) ) ,
216
+ . map ( |e : Arc < Entity > | ( e. uid ( ) . clone ( ) , e ) ) ,
217
217
) ;
218
218
}
219
219
Ok ( Self {
@@ -252,6 +252,7 @@ impl Entities {
252
252
fn to_ejsons ( & self ) -> Result < Vec < EntityJson > > {
253
253
self . entities
254
254
. values ( )
255
+ . map ( Arc :: as_ref)
255
256
. map ( EntityJson :: from_entity)
256
257
. collect :: < std:: result:: Result < _ , JsonSerializationError > > ( )
257
258
. map_err ( Into :: into)
@@ -322,13 +323,13 @@ impl Entities {
322
323
}
323
324
324
325
/// Create a map from EntityUids to Entities, erroring if there are any duplicates
325
- fn create_entity_map ( es : impl Iterator < Item = Entity > ) -> Result < HashMap < EntityUID , Entity > > {
326
+ fn create_entity_map ( es : impl Iterator < Item = Entity > ) -> Result < HashMap < EntityUID , Arc < Entity > > > {
326
327
let mut map = HashMap :: new ( ) ;
327
328
for e in es {
328
329
match map. entry ( e. uid ( ) . clone ( ) ) {
329
330
hash_map:: Entry :: Occupied ( _) => return Err ( EntitiesError :: duplicate ( e. uid ( ) . clone ( ) ) ) ,
330
331
hash_map:: Entry :: Vacant ( v) => {
331
- v. insert ( e ) ;
332
+ v. insert ( Arc :: new ( e ) ) ;
332
333
}
333
334
} ;
334
335
}
@@ -338,10 +339,14 @@ fn create_entity_map(es: impl Iterator<Item = Entity>) -> Result<HashMap<EntityU
338
339
impl IntoIterator for Entities {
339
340
type Item = Entity ;
340
341
341
- type IntoIter = hash_map :: IntoValues < EntityUID , Entity > ;
342
+ type IntoIter = std :: vec :: IntoIter < Entity > ;
342
343
343
344
fn into_iter ( self ) -> Self :: IntoIter {
344
- self . entities . into_values ( )
345
+ self . entities
346
+ . into_values ( )
347
+ . map ( Arc :: unwrap_or_clone)
348
+ . collect :: < Vec < Entity > > ( )
349
+ . into_iter ( )
345
350
}
346
351
}
347
352
0 commit comments