1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
pub trait Printer { fn print(&mut self, text: &str); fn wait(&mut self); } pub struct DummyPrinter; impl Printer for DummyPrinter { fn print(&mut self, _: &str) {} fn wait(&mut self) {} } pub struct RecordPrinter(String); impl RecordPrinter { pub fn new() -> Self { Self(String::with_capacity(8196)) } pub fn text(&self) -> &str { &self.0 } } impl Printer for RecordPrinter { fn print(&mut self, text: &str) { self.0 += text; } fn wait(&mut self) { self.0.push('#'); } }