Skip to main content

relay_knowledge/domain/
entity.rs

1use serde::{Deserialize, Serialize};
2
3/// A minimal entity model used by early graph-building code.
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5pub struct KnowledgeEntity {
6    id: String,
7    label: String,
8}
9
10impl KnowledgeEntity {
11    /// Creates a new knowledge entity with a stable identifier and display label.
12    pub fn new(id: impl Into<String>, label: impl Into<String>) -> Self {
13        Self {
14            id: id.into(),
15            label: label.into(),
16        }
17    }
18
19    /// Returns the stable entity identifier.
20    pub fn id(&self) -> &str {
21        &self.id
22    }
23
24    /// Returns the human-readable entity label.
25    pub fn label(&self) -> &str {
26        &self.label
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[test]
35    fn creates_entity_with_id_and_label() {
36        let entity = KnowledgeEntity::new("entity:rust", "Rust");
37
38        assert_eq!(entity.id(), "entity:rust");
39        assert_eq!(entity.label(), "Rust");
40    }
41}