use alloc::vec::Vec;
use vize_l0::hash::hash_str;
use vize_l0::{String, cstr};
use crate::pass::PassEvent;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Page {
pub name: String,
pub stage: String,
pub pass: String,
pub text: String,
}
#[derive(Debug, Default)]
pub struct Collector {
pub after_change_only: bool,
last_hash: Option<u64>,
pub pages: Vec<Page>,
}
impl Collector {
#[must_use]
pub const fn new(after_change_only: bool) -> Self {
Self {
after_change_only,
last_hash: None,
pages: Vec::new(),
}
}
pub fn seed(&mut self, canonical_text: &str) {
self.last_hash = Some(hash_str(canonical_text));
}
pub fn after_pass(&mut self, event: &PassEvent<'_>, canonical_text: &str) {
let hash = hash_str(canonical_text);
if self.after_change_only && self.last_hash == Some(hash) {
return;
}
self.last_hash = Some(hash);
self.pages.push(Page {
name: cstr!(
"{:03}-{}.{}.folio",
self.pages.len(),
event.pipeline.stage,
event.desc().name
),
stage: String::from(event.pipeline.stage),
pass: String::from(event.desc().name),
text: String::from(canonical_text),
});
}
}