@@ -740,17 +740,16 @@ lazy_static! {
740740}
741741
742742/// An entity is represented as a map of attribute names to values.
743- #[ derive( Clone , CacheWeight , Eq , Serialize ) ]
743+ #[ derive( Clone , CacheWeight , PartialEq , Eq , Serialize ) ]
744744pub struct Entity ( Object < Value > ) ;
745745
746746impl < ' a > IntoIterator for & ' a Entity {
747- type Item = ( & ' a str , & ' a Value ) ;
747+ type Item = ( Word , Value ) ;
748748
749- type IntoIter =
750- std:: iter:: Filter < intern:: ObjectIter < ' a , Value > , fn ( & ( & ' a str , & ' a Value ) ) -> bool > ;
749+ type IntoIter = intern:: ObjectOwningIter < Value > ;
751750
752751 fn into_iter ( self ) -> Self :: IntoIter {
753- ( & self . 0 ) . into_iter ( ) . filter ( | ( k , _ ) | * k != VID_FIELD )
752+ self . 0 . clone ( ) . into_iter ( )
754753 }
755754}
756755
@@ -875,18 +874,10 @@ impl Entity {
875874 }
876875
877876 pub fn get ( & self , key : & str ) -> Option < & Value > {
878- // VID field is private and not visible outside
879- if key == VID_FIELD {
880- return None ;
881- }
882877 self . 0 . get ( key)
883878 }
884879
885880 pub fn contains_key ( & self , key : & str ) -> bool {
886- // VID field is private and not visible outside
887- if key == VID_FIELD {
888- return false ;
889- }
890881 self . 0 . contains_key ( key)
891882 }
892883
@@ -924,8 +915,7 @@ impl Entity {
924915 /// Return the VID of this entity and if its missing or of a type different than
925916 /// i64 it panics.
926917 pub fn vid ( & self ) -> i64 {
927- self . 0
928- . get ( VID_FIELD )
918+ self . get ( VID_FIELD )
929919 . expect ( "the vid must be set" )
930920 . as_int8 ( )
931921 . expect ( "the vid must be set to a valid value" )
@@ -936,6 +926,15 @@ impl Entity {
936926 self . 0 . insert ( VID_FIELD , value. into ( ) )
937927 }
938928
929+ /// Sets the VID if it's not already set. Should be used only for tests.
930+ #[ cfg( debug_assertions) ]
931+ pub fn set_vid_if_empty ( & mut self ) {
932+ let vid = self . get ( VID_FIELD ) ;
933+ if vid. is_none ( ) {
934+ let _ = self . set_vid ( 100 ) . expect ( "the vid should be set" ) ;
935+ }
936+ }
937+
939938 /// Merges an entity update `update` into this entity.
940939 ///
941940 /// If a key exists in both entities, the value from `update` is chosen.
@@ -1059,13 +1058,6 @@ impl Entity {
10591058 }
10601059}
10611060
1062- /// Checks equality of two entities while ignoring the VID fields
1063- impl PartialEq for Entity {
1064- fn eq ( & self , other : & Self ) -> bool {
1065- self . 0 . eq_ignore_key ( & other. 0 , VID_FIELD )
1066- }
1067- }
1068-
10691061/// Convenience methods to modify individual attributes for tests.
10701062/// Production code should not use/need this.
10711063#[ cfg( debug_assertions) ]
@@ -1085,14 +1077,6 @@ impl Entity {
10851077 ) -> Result < Option < Value > , InternError > {
10861078 self . 0 . insert ( name, value. into ( ) )
10871079 }
1088-
1089- /// Sets the VID if it's not already set. Should be used only for tests.
1090- pub fn set_vid_if_empty ( & mut self ) {
1091- let vid = self . 0 . get ( VID_FIELD ) ;
1092- if vid. is_none ( ) {
1093- let _ = self . set_vid ( 100 ) . expect ( "the vid should be set" ) ;
1094- }
1095- }
10961080}
10971081
10981082impl < ' a > From < & ' a Entity > for Cow < ' a , Entity > {
@@ -1284,47 +1268,3 @@ fn fmt_debug() {
12841268 let bi = Value :: BigInt ( scalar:: BigInt :: from ( -17i32 ) ) ;
12851269 assert_eq ! ( "BigInt(-17)" , format!( "{:?}" , bi) ) ;
12861270}
1287-
1288- #[ test]
1289- fn entity_hidden_vid ( ) {
1290- use crate :: schema:: InputSchema ;
1291- let subgraph_id = "oneInterfaceOneEntity" ;
1292- let document = "type Thing @entity {id: ID!, name: String!}" ;
1293- let schema = InputSchema :: raw ( document, subgraph_id) ;
1294-
1295- let entity = entity ! { schema => id: "1" , name: "test" , vid: 3i64 } ;
1296- let debug_str = format ! ( "{:?}" , entity) ;
1297- let entity_str = "Entity { id: String(\" 1\" ), name: String(\" test\" ), vid: Int8(3) }" ;
1298- assert_eq ! ( debug_str, entity_str) ;
1299-
1300- // get returns nothing...
1301- assert_eq ! ( entity. get( VID_FIELD ) , None ) ;
1302- assert_eq ! ( entity. contains_key( VID_FIELD ) , false ) ;
1303- // ...while vid is present
1304- assert_eq ! ( entity. vid( ) , 3i64 ) ;
1305-
1306- // into_iter() misses it too
1307- let mut it = entity. into_iter ( ) ;
1308- assert_eq ! ( Some ( ( "id" , & Value :: String ( "1" . to_string( ) ) ) ) , it. next( ) ) ;
1309- assert_eq ! (
1310- Some ( ( "name" , & Value :: String ( "test" . to_string( ) ) ) ) ,
1311- it. next( )
1312- ) ;
1313- assert_eq ! ( None , it. next( ) ) ;
1314-
1315- let mut entity2 = entity ! { schema => id: "1" , name: "test" , vid: 5i64 } ;
1316- assert_eq ! ( entity2. vid( ) , 5i64 ) ;
1317- // equal with different vid
1318- assert_eq ! ( entity, entity2) ;
1319-
1320- entity2. remove ( VID_FIELD ) ;
1321- // equal if one has no vid
1322- assert_eq ! ( entity, entity2) ;
1323- let debug_str2 = format ! ( "{:?}" , entity2) ;
1324- let entity_str2 = "Entity { id: String(\" 1\" ), name: String(\" test\" ) }" ;
1325- assert_eq ! ( debug_str2, entity_str2) ;
1326-
1327- // set again
1328- _ = entity2. set_vid ( 7i64 ) ;
1329- assert_eq ! ( entity2. vid( ) , 7i64 ) ;
1330- }
0 commit comments