readable errors

This commit is contained in:
Mark
2026-03-24 23:19:02 +01:00
parent da22776f24
commit b23aaf95cf
3 changed files with 81 additions and 18 deletions

View File

@@ -7,15 +7,13 @@ use crate::{
pub struct State<'a> {
pub head_to_body: &'a str,
cache_docs: BTreeMap<&'a Document<'a>, String>,
cache_secs: BTreeMap<&'a Section<'a>, String>,
cache: BTreeMap<&'a Section<'a>, String>,
}
impl<'a> State<'a> {
pub fn new() -> Self {
State {
head_to_body: "</head>\n<body>",
cache_docs: Default::default(),
cache_secs: Default::default(),
cache: Default::default(),
}
}
}
@@ -254,11 +252,6 @@ fn doc_to_impl<'a>(
out: &mut String,
doc_args: &mut DocArgs<'a, '_>,
) {
if let Some(prev) = doc_args.state.cache_docs.get(doc) {
out.push_str(prev);
return;
}
let out_start = out.len();
let depth = doc_args.depth;
let end_at = doc_args.max_len.map(|len| out.len() + len);
for d in depth..=doc.depth {
@@ -285,7 +278,7 @@ fn doc_to_impl<'a>(
out.push_str(&format!("</span>{a}</div>\n"));
}
for section in &doc.sections {
if let Some(prev) = doc_args.state.cache_secs.get(section) {
if let Some(prev) = doc_args.state.cache.get(section) {
out.push_str(prev);
continue;
}
@@ -385,16 +378,12 @@ fn doc_to_impl<'a>(
out.push_str("</div>\n");
doc_args
.state
.cache_secs
.cache
.insert(section, out[section_start..].to_owned());
}
for _ in depth..=doc.depth {
out.push_str("</div>\n");
}
doc_args
.state
.cache_docs
.insert(doc, out[out_start..].to_owned());
}
fn text_to<'a: 'b, 'b>(