codegraph_python/relationships/
implementations.rs

1use serde::{Deserialize, Serialize};
2
3/// Represents a protocol/trait implementation relationship
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5pub struct ImplementationRelation {
6    /// Name of the implementing class
7    pub implementer: String,
8
9    /// Name of the trait/protocol being implemented
10    pub trait_name: String,
11
12    /// Line number where implementation is declared
13    pub line: usize,
14}
15
16impl ImplementationRelation {
17    /// Create a new implementation relation
18    pub fn new(implementer: impl Into<String>, trait_name: impl Into<String>, line: usize) -> Self {
19        Self {
20            implementer: implementer.into(),
21            trait_name: trait_name.into(),
22            line,
23        }
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30
31    #[test]
32    fn test_implementation_relation_new() {
33        let implementation = ImplementationRelation::new("MyClass", "Serializable", 10);
34        assert_eq!(implementation.implementer, "MyClass");
35        assert_eq!(implementation.trait_name, "Serializable");
36        assert_eq!(implementation.line, 10);
37    }
38}