reactive_graph_graph/instances/entities/
entity_instance_container.rs

1use uuid::Uuid;
2
3use crate::AddEntityInstanceError;
4use crate::EntityInstance;
5use crate::EntityInstances;
6use crate::RemoveEntityInstanceError;
7use crate::UpdateEntityInstanceError;
8
9/// Container for entity instances.
10pub trait EntityInstanceContainer {
11    /// Returns the entity instances.
12    fn entity_instances(&self) -> EntityInstances;
13
14    // TODO:
15    // fn get_entity_instance_ids(&self) -> DashSet<Uuid>;
16
17    // TODO:
18    // fn get_entity_type_ids(&self) -> EntityTypeIds;
19
20    /// Returns true, if the container has an entity instance with the given id.
21    fn has_entity_instance(&self, id: Uuid) -> bool;
22
23    /// Adds the given entity instance.
24    fn add_entity_instance(&self, entity_instance: EntityInstance) -> Result<(), AddEntityInstanceError>;
25
26    /// Updates the entity instance with the id of the given entity instance.
27    fn update_entity_instance(&self, id: Uuid, entity_instance: EntityInstance) -> Result<(Uuid, EntityInstance), UpdateEntityInstanceError>;
28
29    /// Removes the entity instance with the given id.
30    fn remove_entity_instance(&self, id: Uuid) -> Result<Option<(Uuid, EntityInstance)>, RemoveEntityInstanceError>;
31
32    // TODO: Replaces the id of the entity instance and in all relation outbounds and relation inbounds.
33    // fn set_entity_instance_id(&self, id: Uuid)
34}
35
36/// Collection of a type which contains entity instances.
37// TODO: Rename T to TypeId
38// TODO: Trait bound: T: NamespacedTypeGetter
39// TODO: Trait bound: Self: NamespacedTypeContainer
40pub trait NamespacedTypeEntityInstanceContainer<
41    T,
42    NamespacedTypeDoesNotExistError,
43    AddEntityInstanceError,
44    UpdateEntityInstanceError,
45    RemoveEntityInstanceError,
46>
47{
48    /// Returns the entity instances.
49    fn entity_instances(&self, ty: &T) -> Result<EntityInstances, NamespacedTypeDoesNotExistError>;
50
51    // TODO:
52    // fn get_entity_instance_ids(&self, ty: &T) -> Result<DashSet<Uuid>, NamespacedTypeDoesNotExistError>;
53
54    // TODO:
55    // fn get_entity_type_ids(&self, ty: &T) -> Result<EntityTypeIds, NamespacedTypeDoesNotExistError>;
56
57    /// Returns true, if an entity instance with the given id exists.
58    fn has_entity_instance(&self, ty: &T, id: Uuid) -> Result<bool, NamespacedTypeDoesNotExistError>;
59
60    /// Adds the given entity instance.
61    fn add_entity_instance(&self, ty: &T, entity_instance: EntityInstance) -> Result<(), AddEntityInstanceError>;
62
63    /// Updates the entity instance with the id of the given entity instance.
64    fn update_entity_instance(&self, ty: &T, id: Uuid, entity_instance: EntityInstance) -> Result<(Uuid, EntityInstance), UpdateEntityInstanceError>;
65
66    /// Removes the entity instance with the given id.
67    fn remove_entity_instance(&self, ty: &T, id: Uuid) -> Result<Option<(Uuid, EntityInstance)>, RemoveEntityInstanceError>;
68}