egml_core/model/base/
reference.rs1use crate::model::base::{
2 AssociationAttributes, HasAssociationAttributes, HasAssociationAttributesMut,
3 HasOwnershipAttributes, HasOwnershipAttributesMut, OwnershipAttributes,
4};
5use crate::model::xlink::HRef;
6
7#[derive(Debug, Clone, PartialEq, Default)]
15pub struct Reference {
16 pub association: AssociationAttributes,
17 pub ownership: OwnershipAttributes,
18}
19
20impl Reference {
21 pub fn new(href: HRef) -> Self {
23 Self {
24 association: AssociationAttributes::new_href(href),
25 ownership: OwnershipAttributes::default(),
26 }
27 }
28}
29
30impl HasAssociationAttributes for Reference {
31 fn association(&self) -> &AssociationAttributes {
32 &self.association
33 }
34}
35
36impl HasAssociationAttributesMut for Reference {
37 fn association_mut(&mut self) -> &mut AssociationAttributes {
38 &mut self.association
39 }
40}
41
42impl HasOwnershipAttributes for Reference {
43 fn ownership(&self) -> &OwnershipAttributes {
44 &self.ownership
45 }
46}
47
48impl HasOwnershipAttributesMut for Reference {
49 fn ownership_mut(&mut self) -> &mut OwnershipAttributes {
50 &mut self.ownership
51 }
52}
53
54#[cfg(test)]
55mod tests {
56 use super::Reference;
57 use crate::model::base::{
58 HasAssociationAttributes, HasAssociationAttributesMut, HasOwnershipAttributes,
59 };
60 use crate::model::xlink::HRef;
61
62 #[test]
63 fn new_sets_href() {
64 let reference = Reference::new(HRef::from_local("some-id"));
65 assert_eq!(reference.href(), Some(&HRef::from_local("some-id")));
66 assert!(!reference.owns());
67 }
68
69 #[test]
70 fn set_role_updates_association() {
71 let mut reference = Reference::new(HRef::from_local("some-id"));
72 reference.set_role("http://example.com/role");
73 assert_eq!(reference.role(), Some("http://example.com/role"));
74 }
75}