Store member groups in BTreeMap
With this patch, we change the type of the Doc::groups field to BTreeMap<ItemType, Vec<MemberGroup>>. This makes it clearer and easier to read. We also reorder the ItemType module so that the output order of the member groups is not changed by this patch.
This commit is contained in:
parent
e74ef86ebe
commit
8e97ad269b
38
src/doc.rs
38
src/doc.rs
@ -1,6 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2020 Robin Krahl <robin.krahl@ireas.org>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use std::collections;
|
||||
use std::convert;
|
||||
use std::fmt;
|
||||
use std::ops;
|
||||
@ -31,26 +32,35 @@ pub struct Code(String);
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub enum ItemType {
|
||||
Module,
|
||||
// module members
|
||||
ExternCrate,
|
||||
Import,
|
||||
Primitive,
|
||||
Module,
|
||||
Macro,
|
||||
Struct,
|
||||
Enum,
|
||||
Function,
|
||||
Typedef,
|
||||
Constant,
|
||||
Static,
|
||||
Trait,
|
||||
Impl,
|
||||
TyMethod,
|
||||
Method,
|
||||
StructField,
|
||||
Variant,
|
||||
Macro,
|
||||
Primitive,
|
||||
AssocType,
|
||||
Constant,
|
||||
AssocConst,
|
||||
Function,
|
||||
Typedef,
|
||||
Union,
|
||||
|
||||
// struct and union members
|
||||
StructField,
|
||||
|
||||
// enum members
|
||||
Variant,
|
||||
|
||||
// associated items
|
||||
AssocType,
|
||||
AssocConst,
|
||||
Method,
|
||||
Impl,
|
||||
|
||||
// other items
|
||||
TyMethod,
|
||||
ForeignType,
|
||||
Keyword,
|
||||
OpaqueTy,
|
||||
@ -65,7 +75,7 @@ pub struct Doc {
|
||||
pub ty: ItemType,
|
||||
pub description: Option<Text>,
|
||||
pub definition: Option<Code>,
|
||||
pub groups: Vec<(ItemType, Vec<MemberGroup>)>,
|
||||
pub groups: collections::BTreeMap<ItemType, Vec<MemberGroup>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -88,7 +88,7 @@ impl Parser {
|
||||
];
|
||||
for (ty, groups) in members.into_iter() {
|
||||
if !groups.is_empty() {
|
||||
doc.groups.push((ty, groups));
|
||||
doc.groups.insert(ty, groups);
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ impl Parser {
|
||||
let mut group = doc::MemberGroup::new(None);
|
||||
group.members = get_members(&self.document, name, *item_type)?;
|
||||
if !group.members.is_empty() {
|
||||
doc.groups.push((*item_type, vec![group]));
|
||||
doc.groups.insert(*item_type, vec![group]);
|
||||
}
|
||||
}
|
||||
Ok(doc)
|
||||
|
Loading…
Reference in New Issue
Block a user