Skip to content

Commit a821750

Browse files
committed
Stop depending on serde_json
1 parent dc37d3d commit a821750

File tree

6 files changed

+2235
-2227
lines changed

6 files changed

+2235
-2227
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

derive/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ maplit = "1.0.2"
2121
once_cell = "1.10.0"
2222
textwrap = { version = "0.15.0", default-features = false }
2323
indexmap = "1.8.1"
24-
serde_json = "1.0.79"
2524
itertools = "0.10.3"

derive/docs.json

Lines changed: 0 additions & 2213 deletions
This file was deleted.

derive/docs.rsinc

Lines changed: 2213 additions & 0 deletions
Large diffs are not rendered by default.

derive/src/doc.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
use once_cell::sync::Lazy;
2+
use std::collections::HashMap;
13
pub(crate) type Result = std::result::Result<Option<&'static str>, ()>;
24

35
pub(crate) fn try_read(path: &str) -> Result {
4-
static DATABASE: once_cell::sync::OnceCell<std::collections::HashMap<String, Option<String>>> =
5-
once_cell::sync::OnceCell::new();
6-
let db = DATABASE.get_or_init(|| {
7-
let raw = include_str!("../docs.json");
8-
serde_json::from_str(raw).expect("docs.json must be a valid json file")
6+
static DATABASE: Lazy<HashMap<&str, Option<&str>>> = Lazy::new(|| {
7+
let data = include!("../docs.rsinc");
8+
let mut map = HashMap::with_capacity(data.len());
9+
for (item, doc) in data {
10+
map.insert(item, doc);
11+
}
12+
map
913
});
10-
let data = db.get(path).ok_or(())?;
11-
Ok(data.as_ref().map(|s| s.as_str()))
14+
DATABASE.get(path).copied().ok_or(())
1215
}
1316

1417
pub(crate) fn try_module_item(module: &str, item: &str) -> Result {

scripts/generate_docs.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,26 @@ def traverse_all():
108108

109109

110110
def docs():
111-
docs = {".".join(names): doc for names, doc in traverse_all()}
112-
return docs
111+
return ((".".join(names), doc) for names, doc in traverse_all())
113112

114113

115114
if __name__ == "__main__":
116-
import json
117115
import sys
116+
import json
118117

119118
try:
120119
out_path = sys.argv[1]
121120
except IndexError:
122121
out_path = "-"
123122

124-
dump = json.dumps(docs(), indent=4, sort_keys=True)
123+
def dump(docs):
124+
yield "[\n"
125+
for name, doc in docs:
126+
if doc is None:
127+
yield f" ({json.dumps(name)}, None),\n"
128+
else:
129+
yield f" ({json.dumps(name)}, Some({json.dumps(doc)})),\n"
130+
yield "]\n"
131+
125132
out_file = open(out_path, "w") if out_path != "-" else sys.stdout
126-
out_file.write(dump)
133+
out_file.writelines(dump(docs()))

0 commit comments

Comments
 (0)