Resolves a path to an item in the registry. # Errors Returns a `ResolutionError` if: - The path cannot be resolved to any item - The path resolves to multiple items (ambiguous resolution) - Any part of the path fails to resolve correctly
(
&self,
path: impl IntoIterator<Item = Symbol<'heap>>,
universe: Universe,
)
| 175 | /// - The path resolves to multiple items (ambiguous resolution) |
| 176 | /// - Any part of the path fails to resolve correctly |
| 177 | pub fn resolve( |
| 178 | &self, |
| 179 | path: impl IntoIterator<Item = Symbol<'heap>>, |
| 180 | universe: Universe, |
| 181 | ) -> Result<Item<'heap>, ResolutionError<'heap>> { |
| 182 | let resolver = Resolver { |
| 183 | registry: self, |
| 184 | options: ResolverOptions { |
| 185 | mode: ResolverMode::Single(universe), |
| 186 | suggestions: true, |
| 187 | }, |
| 188 | }; |
| 189 | |
| 190 | let mut iter = resolver.resolve_absolute(path)?; |
| 191 | let item = iter.next().unwrap_or_else(|| { |
| 192 | unreachable!("ResolveIter guarantees at least one item is returned") |
| 193 | }); |
| 194 | |
| 195 | if iter.next().is_some() { |
| 196 | Err(ResolutionError::Ambiguous(item)) |
| 197 | } else { |
| 198 | match item { |
| 199 | Reference::Binding(_) => { |
| 200 | unreachable!("Absolute path cannot point to a local binding") |
| 201 | } |
| 202 | Reference::Item(item) => Ok(item), |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | /// Attempts to resolve a path to an item in the registry. |
| 208 | /// |