reactive_graph_graph/instances/relations/
relation_instance_container.rs

1use uuid::Uuid;
2
3use crate::AddRelationInstanceError;
4use crate::RelationInstance;
5use crate::RelationInstanceId;
6use crate::RelationInstances;
7use crate::RemoveRelationInstanceError;
8use crate::UpdateRelationInstanceError;
9
10/// Container for relation instances.
11pub trait RelationInstanceContainer {
12    /// Returns the relation instances.
13    fn relation_instances(&self) -> RelationInstances;
14
15    /// Returns true, if a relation instance exists which uses an entity instance with the given id.
16    fn has_relation_which_uses_entity_instance(&self, id: Uuid) -> bool;
17
18    /// Returns true, if a relation instance with the given id exists.
19    fn has_relation_instance(&self, id: &RelationInstanceId) -> bool;
20
21    /// Adds the given relation instance.
22    fn add_relation_instance(&self, relation_instance: RelationInstance) -> Result<(), AddRelationInstanceError>;
23
24    /// Updates the relation instance with the given id with the given relation instance.
25    fn update_relation_instance(
26        &self,
27        id: &RelationInstanceId,
28        relation_instance: RelationInstance,
29    ) -> Result<(RelationInstanceId, RelationInstance), UpdateRelationInstanceError>;
30
31    /// Removes the relation instance with the given id.
32    fn remove_relation_instance(&self, id: &RelationInstanceId) -> Result<Option<(RelationInstanceId, RelationInstance)>, RemoveRelationInstanceError>;
33}
34
35/// Collection of a type which contains relation instances.
36// TODO: Rename T to TypeId
37// TODO: Trait bound: T: NamespacedTypeGetter
38// TODO: Trait bound: Self: NamespacedTypeContainer
39pub trait NamespacedTypeRelationInstanceContainer<
40    T,
41    NamespacedTypeDoesNotExistError,
42    AddRelationInstanceError,
43    UpdateRelationInstanceError,
44    RemoveRelationInstanceError,
45>
46{
47    /// Returns the relation instances.
48    fn relation_instances(&self, ty: &T) -> Result<RelationInstances, NamespacedTypeDoesNotExistError>;
49
50    /// Returns true, if a relation instance exists which uses an entity instance with the given id.
51    fn has_relation_which_uses_entity_instance(&self, ty: &T, id: Uuid) -> Result<bool, NamespacedTypeDoesNotExistError>;
52
53    /// Returns true, if a relation instance with the given id exists.
54    fn has_relation_instance(&self, ty: &T, id: &RelationInstanceId) -> Result<bool, NamespacedTypeDoesNotExistError>;
55
56    /// Adds the given relation instance.
57    fn add_relation_instance(&self, ty: &T, relation_instance: RelationInstance) -> Result<(), AddRelationInstanceError>;
58
59    /// Updates the relation instance with the id of the given relation instance.
60    fn update_relation_instance(
61        &self,
62        ty: &T,
63        id: &RelationInstanceId,
64        relation_instance: RelationInstance,
65    ) -> Result<(RelationInstanceId, RelationInstance), UpdateRelationInstanceError>;
66
67    /// Removes the relation instance with the given id.
68    fn remove_relation_instance(&self, ty: &T, id: &RelationInstanceId) -> Result<Option<(RelationInstanceId, RelationInstance)>, RemoveRelationInstanceError>;
69}