2019-10-07 22:16:04 +08:00
|
|
|
use std::{error, fmt, io};
|
2019-10-03 21:04:11 +08:00
|
|
|
use crate::serde::SerializerError;
|
|
|
|
|
2019-10-03 23:33:15 +08:00
|
|
|
pub type MResult<T> = Result<T, Error>;
|
|
|
|
|
2019-10-03 21:04:11 +08:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
2019-10-07 22:16:04 +08:00
|
|
|
Io(io::Error),
|
2019-10-03 21:04:11 +08:00
|
|
|
SchemaDiffer,
|
|
|
|
SchemaMissing,
|
|
|
|
WordIndexMissing,
|
|
|
|
MissingDocumentId,
|
2019-10-07 22:16:04 +08:00
|
|
|
Rkv(rkv::StoreError),
|
|
|
|
Fst(fst::Error),
|
|
|
|
RmpDecode(rmp_serde::decode::Error),
|
|
|
|
RmpEncode(rmp_serde::encode::Error),
|
|
|
|
Bincode(bincode::Error),
|
|
|
|
Serializer(SerializerError),
|
2019-10-07 23:48:26 +08:00
|
|
|
UnsupportedOperation(UnsupportedOperation),
|
2019-10-07 22:16:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<io::Error> for Error {
|
|
|
|
fn from(error: io::Error) -> Error {
|
|
|
|
Error::Io(error)
|
|
|
|
}
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<rkv::StoreError> for Error {
|
|
|
|
fn from(error: rkv::StoreError) -> Error {
|
2019-10-07 22:16:04 +08:00
|
|
|
Error::Rkv(error)
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<fst::Error> for Error {
|
|
|
|
fn from(error: fst::Error) -> Error {
|
2019-10-07 22:16:04 +08:00
|
|
|
Error::Fst(error)
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<rmp_serde::decode::Error> for Error {
|
|
|
|
fn from(error: rmp_serde::decode::Error) -> Error {
|
2019-10-07 22:16:04 +08:00
|
|
|
Error::RmpDecode(error)
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<rmp_serde::encode::Error> for Error {
|
|
|
|
fn from(error: rmp_serde::encode::Error) -> Error {
|
2019-10-07 22:16:04 +08:00
|
|
|
Error::RmpEncode(error)
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<bincode::Error> for Error {
|
|
|
|
fn from(error: bincode::Error) -> Error {
|
2019-10-07 22:16:04 +08:00
|
|
|
Error::Bincode(error)
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<SerializerError> for Error {
|
|
|
|
fn from(error: SerializerError) -> Error {
|
2019-10-07 22:16:04 +08:00
|
|
|
Error::Serializer(error)
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 23:48:26 +08:00
|
|
|
impl From<UnsupportedOperation> for Error {
|
|
|
|
fn from(op: UnsupportedOperation) -> Error {
|
|
|
|
Error::UnsupportedOperation(op)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 21:04:11 +08:00
|
|
|
impl fmt::Display for Error {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use self::Error::*;
|
|
|
|
match self {
|
2019-10-07 22:16:04 +08:00
|
|
|
Io(e) => write!(f, "{}", e),
|
2019-10-03 21:04:11 +08:00
|
|
|
SchemaDiffer => write!(f, "schemas differ"),
|
|
|
|
SchemaMissing => write!(f, "this index does not have a schema"),
|
|
|
|
WordIndexMissing => write!(f, "this index does not have a word index"),
|
|
|
|
MissingDocumentId => write!(f, "document id is missing"),
|
2019-10-07 22:16:04 +08:00
|
|
|
Rkv(e) => write!(f, "rkv error; {}", e),
|
|
|
|
Fst(e) => write!(f, "fst error; {}", e),
|
|
|
|
RmpDecode(e) => write!(f, "rmp decode error; {}", e),
|
|
|
|
RmpEncode(e) => write!(f, "rmp encode error; {}", e),
|
|
|
|
Bincode(e) => write!(f, "bincode error; {}", e),
|
|
|
|
Serializer(e) => write!(f, "serializer error; {}", e),
|
2019-10-07 23:48:26 +08:00
|
|
|
UnsupportedOperation(op) => write!(f, "unsupported operation; {}", op),
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl error::Error for Error { }
|
|
|
|
|
2019-10-07 23:48:26 +08:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum UnsupportedOperation {
|
|
|
|
SchemaAlreadyExists,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for UnsupportedOperation {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use self::UnsupportedOperation::*;
|
|
|
|
match self {
|
|
|
|
SchemaAlreadyExists => write!(f, "Cannot update index which already have a schema"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|