use core::fmt::Write;
use super::{PassEvent, PassObserver, Pipeline};
use crate::dump::{Dump, Mode as DumpMode};
#[derive(Debug)]
pub struct DumpObserver<W> {
pub sink: W,
pub mode: DumpMode,
pub pages: u32,
}
impl<W: Write> DumpObserver<W> {
#[must_use]
pub const fn new(sink: W) -> Self {
Self {
sink,
mode: DumpMode::Full,
pages: 0,
}
}
#[must_use]
pub const fn with_mode(sink: W, mode: DumpMode) -> Self {
Self {
sink,
mode,
pages: 0,
}
}
pub fn page<A: Dump>(
&mut self,
event: &PassEvent<'_>,
artifact: &A,
) -> Result<(), core::fmt::Error> {
writeln!(
self.sink,
"; after {}.{} (walk {})",
event.pipeline.stage,
event.desc().name,
event.group_index
)?;
artifact.print(&mut self.sink, self.mode)?;
self.pages += 1;
Ok(())
}
}
impl<W> PassObserver for DumpObserver<W> {
fn before_pipeline(&mut self, _pipeline: &Pipeline) {}
}