Decompose this name into its components (from root to leaf).
(&self)
| 181 | } |
| 182 | /// Decompose this name into its components (from root to leaf). |
| 183 | pub fn components(&self) -> Vec<NameComponent> { |
| 184 | let mut components = Vec::new(); |
| 185 | let mut current = self; |
| 186 | loop { |
| 187 | match current.as_data() { |
| 188 | NameData::Anonymous(_) => break, |
| 189 | NameData::Str(pre, s, _) => { |
| 190 | components.push(NameComponent::Str(s.clone())); |
| 191 | current = pre; |
| 192 | }, |
| 193 | NameData::Num(pre, n, _) => { |
| 194 | components.push(NameComponent::Num(n.clone())); |
| 195 | current = pre; |
| 196 | }, |
| 197 | } |
| 198 | } |
| 199 | components.reverse(); |
| 200 | components |
| 201 | } |
| 202 | |
| 203 | /// Strip a prefix from this name, returning the suffix components. |
| 204 | pub fn strip_prefix(&self, prefix: &Name) -> Option<Vec<NameComponent>> { |
no test coverage detected