use crate::Reader;
use std::cell::Cell;
thread_local! {
pub static OUTPUT: Cell<String> = Cell::default();
}
pub fn trace_log(msg: &str) {
OUTPUT.with(|cell| {
let mut buf = cell.take();
buf.push_str(msg);
buf.push('\n');
if buf.len() > 20 * 1024 * 1024 {
buf.clear();
buf.push_str("[truncated output]\n");
}
cell.set(buf);
});
}
#[derive(Debug)]
pub struct SlowReader<R: Reader>(pub R);
impl<R: Reader> Reader for SlowReader<R> {
type Error = R::Error;
fn read_byte(&mut self) -> Result<Option<u8>, Self::Error> {
self.0.read_byte()
}
fn try_read_string(&mut self, s: &[u8], case_sensitive: bool) -> Result<bool, Self::Error> {
self.0.try_read_string(s, case_sensitive)
}
}