fslutils 0.1.1

Utility functions for inspecting fossil checkouts.
Documentation
use std::{fmt, io};

#[derive(Debug)]
pub enum Error {
  /// Unable to convert output string to UTF-8.
  Encoding(String),

  /// [`std::io::Error`] error.
  IO(io::Error),

  /// Missing expected information.
  Missing(String)
}

impl std::error::Error for Error {}

impl Error {
  pub fn encoding(s: impl Into<String>) -> Self {
    Self::Encoding(s.into())
  }

  pub fn missing(s: impl Into<String>) -> Self {
    Self::Missing(s.into())
  }
}

impl From<io::Error> for Error {
  fn from(err: io::Error) -> Self {
    Self::IO(err)
  }
}

impl fmt::Display for Error {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    match self {
      Self::Encoding(s) => write!(f, "Not UTF-8: {s}"),
      Self::IO(e) => write!(f, "I/O; {e}"),
      Self::Missing(s) => write!(f, "Missing {s}")
    }
  }
}

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :