Update tests with basic init
This commit is contained in:
53
src/debug.rs
Normal file
53
src/debug.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use std::num::NonZeroUsize;
|
||||
|
||||
pub struct DebugLog {
|
||||
current: String,
|
||||
history: Vec<String>,
|
||||
max_history: Option<NonZeroUsize>,
|
||||
pos: usize,
|
||||
}
|
||||
|
||||
impl DebugLog {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
current: String::new(),
|
||||
history: vec![],
|
||||
max_history: None,
|
||||
pos: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rotate(&mut self) {
|
||||
let rot = std::mem::take(&mut self.current);
|
||||
if let Some(max) = self.max_history {
|
||||
if self.history.len() < max.into() {
|
||||
self.history.push(rot);
|
||||
} else {
|
||||
self.history[self.pos] = rot;
|
||||
self.pos = (self.pos + 1) % max.get();
|
||||
}
|
||||
} else {
|
||||
self.history.push(rot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Write for DebugLog {
|
||||
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
||||
self.current.write_str(s)
|
||||
}
|
||||
|
||||
fn write_char(&mut self, c: char) -> std::fmt::Result {
|
||||
self.current.write_char(c)
|
||||
}
|
||||
|
||||
fn write_fmt(&mut self, args: std::fmt::Arguments<'_>) -> std::fmt::Result {
|
||||
self.current.write_fmt(args)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DebugLog {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user