1use std::collections::HashMap;
2
3use crate::style::StyleSpec;
4
5#[derive(Clone, Default, Debug)]
9pub struct CaptureMap {
10 flat: HashMap<String, StyleSpec>,
11}
12
13impl CaptureMap {
14 pub(crate) fn from_map(flat: HashMap<String, StyleSpec>) -> Self {
15 Self { flat }
16 }
17
18 pub fn get(&self, capture: &str) -> Option<&StyleSpec> {
20 self.flat.get(capture)
21 }
22
23 pub fn resolve(&self, capture: &str) -> Option<&StyleSpec> {
25 let mut key = capture;
26 loop {
27 if let Some(spec) = self.flat.get(key) {
28 return Some(spec);
29 }
30 {
31 let pos = key.rfind('.')?;
32 key = &key[..pos]
33 }
34 }
35 }
36}