strval 0.5.0

Parse strings into values
Documentation
use std::fmt;

/// Crate-specific errors.
#[derive(Debug)]
pub enum Error {
  Invalid(String),
  OutOfBounds(String)
}

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

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

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

impl fmt::Display for Error {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    match self {
      Self::Invalid(s) => write!(f, "Invalid value ({s})"),
      Self::OutOfBounds(s) => write!(f, "Out of bounds ({s})")
    }
  }
}

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