Skip to content

Commit f2246ee

Browse files
committed
feat: extract links and framings from overlays in OCABundleInfo constructor
1 parent db54511 commit f2246ee

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/lib.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub struct OCABundleInfo {
100100
attributes: HashMap<String, Attribute>,
101101
pub meta: HashMap<String, HashMap<String, String>>,
102102
pub links: Vec<overlay::Link>,
103-
pub framing: Vec<overlay::AttributeFraming>,
103+
pub framings: Vec<overlay::AttributeFraming>,
104104
}
105105

106106
impl OCABundleInfo {
@@ -113,11 +113,37 @@ impl OCABundleInfo {
113113
})
114114
}
115115

116+
let mut overlays = bundle.overlays.clone();
117+
let links: Vec<overlay::Link> = overlays
118+
.iter_mut()
119+
.filter(|o| o.as_any().downcast_ref::<overlay::Link>().is_some())
120+
.map(|o| {
121+
o.as_any()
122+
.downcast_ref::<overlay::Link>()
123+
.unwrap()
124+
.to_owned()
125+
})
126+
.collect();
127+
let framings: Vec<overlay::AttributeFraming> = overlays
128+
.iter_mut()
129+
.filter(|o| {
130+
o.as_any()
131+
.downcast_ref::<overlay::AttributeFraming>()
132+
.is_some()
133+
})
134+
.map(|o| {
135+
o.as_any()
136+
.downcast_ref::<overlay::AttributeFraming>()
137+
.unwrap()
138+
.to_owned()
139+
})
140+
.collect();
141+
116142
Self {
117143
attributes: oca_box.attributes,
118144
meta,
119-
links: vec![],
120-
framing: vec![],
145+
links,
146+
framings,
121147
}
122148
}
123149

tests/captured_data_validation.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ fn building_from_ocafile() -> Result<(), Box<dyn std::error::Error>> {
2121
oca_bundle.info().attributes().for_each(|attr| {
2222
println!("{:?}", attr);
2323
});
24+
println!("links: {:?}", oca_bundle.info().links);
25+
println!("framings: {:?}", oca_bundle.info().framings);
2426
println!("{}", oca_bundle.get_json_bundle());
2527

2628
Ok(())

0 commit comments

Comments
 (0)