mango_core/
stdout.rs

1use core::fmt;
2
3// pub None = core::option::Option<fn(&str) -> fmt::Result>::None;
4
5/// Holder of a static printing function. Mainly intended to hold STDOUT.
6#[derive(Default)]
7pub struct StaticPrinter
8{
9  printer: Option<fn(&str) -> fmt::Result>,
10}
11
12impl StaticPrinter
13{
14  /// Set the printer function, this is used to print messages.
15  pub fn set_printer_fn(&mut self, cb: fn(&str) -> fmt::Result)
16  {
17    self.printer = Some(cb);
18  }
19}
20
21impl fmt::Write for StaticPrinter
22{
23  fn write_str(&mut self, x: &str) -> fmt::Result
24  {
25    if let Some(cb) = self.printer
26    {
27      cb(x)
28    }
29    else
30    {
31      Ok(())
32    }
33  }
34}