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
use std::fmt;

#[derive(Clone)]
pub struct ParseError {
  pub message: String,
}

fn fmt(f: &mut fmt::Formatter, msg: &str) -> Result<(), fmt::Error> {
  write!(f, "{}", msg)
}

impl fmt::Debug for ParseError {
  fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
    fmt(f, &self.message)
  }
}

impl fmt::Display for ParseError {
  fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
    fmt(f, &self.message)
  }
}

pub fn make_parse_err(s: &str, col_type: &str) -> ParseError {
  ParseError { message: format!("cannot parse string `{}` as {}", s, col_type) }
}

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