igo-rs 0.2.2

Pure Rust port of the Igo, a POS(Part-Of-Speech) tagger for Japanese (日本語 形態素解析).
Documentation
mod worddic;
mod charcategory;
pub mod matrix;

pub use self::worddic::*;
pub use self::charcategory::*;


use std;
use std::error;
use std::error::Error;
use std::fmt;
use std::convert::From;
use std::io;
use std::path::PathBuf;
use std::borrow::Cow;
use glob;

#[derive(Debug)]
pub enum AppError {
    Message(String),
    Io(io::Error),
    Parse {
        message: String,
        path: PathBuf,
        line_number: i32
    }
}

pub type AppResult<T> = Result<T, AppError>;

impl fmt::Display for AppError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            AppError::Message(ref err) => write!(f, "error: {}", err),
            AppError::Io(ref err) => write!(f, "IO error: {}", err),
            AppError::Parse { ref message, ref path, ref line_number } =>
                write!(f, "{}\t{{file: {}, line: {}}}", message, path.display(), line_number),
        }
    }
}

impl error::Error for AppError {
    fn description(&self) -> &str {
        match *self {
            AppError::Message(ref s) => s,
            AppError::Io(ref err) => err.description(),
            AppError::Parse { ref message, .. } => message,
        }
    }

    fn cause(&self) -> Option<&error::Error> {
        match *self {
            AppError::Message(_) => None,
            AppError::Io(ref err) => Some(err),
            AppError::Parse { .. } => None,
        }
    }
}

impl From<String> for AppError {
    fn from(e: String) -> Self {
        AppError::Message(e)
    }
}

impl<'a> From<&'a str> for AppError {
    fn from(e: &str) -> Self {
        AppError::Message(e.to_string())
    }
}

impl From<Cow<'static, str>> for AppError {
    fn from(e: Cow<'static, str>) -> Self {
        AppError::Message(e.to_string())
    }
}

impl From<io::Error> for AppError {
    fn from(e: io::Error) -> Self {
        AppError::Io(e)
    }
}

impl From<glob::PatternError> for AppError {
    fn from(e: glob::PatternError) -> Self {
        AppError::Message(e.description().to_string())
    }
}

impl From<std::num::ParseIntError> for AppError {
    fn from(e: std::num::ParseIntError) -> Self {
        AppError::Message(e.description().to_string())
    }
}