mango-core 0.2.1

Core Libraries for the mango operationg system.
Documentation
use core::fmt;

// pub None = core::option::Option<fn(&str) -> fmt::Result>::None;

/// Holder of a static printing function. Mainly intended to hold STDOUT.
#[derive(Default)]
pub struct StaticPrinter
{
  printer: Option<fn(&str) -> fmt::Result>,
}

impl StaticPrinter
{
  /// Set the printer function, this is used to print messages.
  pub fn set_printer_fn(&mut self, cb: fn(&str) -> fmt::Result)
  {
    self.printer = Some(cb);
  }
}

impl fmt::Write for StaticPrinter
{
  fn write_str(&mut self, x: &str) -> fmt::Result
  {
    if let Some(cb) = self.printer
    {
      cb(x)
    }
    else
    {
      Ok(())
    }
  }
}