Builds an index of the given `callables` and returns a new collection of help topics.
(callables: &HashMap<SymbolKey, Rc<CallableMetadata>>)
| 310 | impl Topics { |
| 311 | /// Builds an index of the given `callables` and returns a new collection of help topics. |
| 312 | fn new(callables: &HashMap<SymbolKey, Rc<CallableMetadata>>) -> Self { |
| 313 | fn insert(topics: &mut Trie<String, Box<dyn Topic>>, topic: Box<dyn Topic>) { |
| 314 | let key = topic.name().to_ascii_uppercase(); |
| 315 | topics.insert(key, topic); |
| 316 | } |
| 317 | |
| 318 | let mut topics = Trie::default(); |
| 319 | |
| 320 | { |
| 321 | let mut index = BTreeMap::default(); |
| 322 | |
| 323 | for (title, content) in parse_lang_reference(LANG_MD) { |
| 324 | let topic = LanguageTopic { name: title, text: content }; |
| 325 | index.insert(topic.name.to_owned(), topic.text.lines().next().unwrap()); |
| 326 | insert(&mut topics, Box::from(topic)); |
| 327 | } |
| 328 | |
| 329 | insert( |
| 330 | &mut topics, |
| 331 | Box::from(CategoryTopic { |
| 332 | name: "Language reference", |
| 333 | description: "General language topics", |
| 334 | index, |
| 335 | }), |
| 336 | ); |
| 337 | } |
| 338 | |
| 339 | let mut categories = HashMap::new(); |
| 340 | for metadata in callables.values() { |
| 341 | let category_title = metadata.category().lines().next().unwrap(); |
| 342 | categories.entry(category_title).or_insert_with(Vec::default).push(metadata.clone()); |
| 343 | |
| 344 | let name = match metadata.return_type() { |
| 345 | None => metadata.name().to_owned(), |
| 346 | Some(return_type) => format!("{}{}", metadata.name(), return_type.annotation()), |
| 347 | }; |
| 348 | |
| 349 | insert(&mut topics, Box::from(CallableTopic { name, metadata: metadata.clone() })); |
| 350 | } |
| 351 | for (name, metadatas) in categories.into_iter() { |
| 352 | let description = metadatas.first().expect("Must have at least one symbol").category(); |
| 353 | let index = callables_to_index(&metadatas); |
| 354 | insert(&mut topics, Box::from(CategoryTopic { name, description, index })); |
| 355 | } |
| 356 | |
| 357 | Self(topics) |
| 358 | } |
| 359 | |
| 360 | /// Returns the given topic named `name`, where `name` can be a prefix. |
| 361 | /// |
nothing calls this directly
no test coverage detected