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:
Robin Krahl 2020-08-17 13:53:41 +02:00
parent e74ef86ebe
commit 8e97ad269b
No known key found for this signature in database
GPG Key ID: 8E9B0870524F69D8
2 changed files with 26 additions and 16 deletions

View File

@ -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)]

View File

@ -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)