pub type LengthResult<T> = Result<T, LengthError>;
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum LengthErrorKind {
LengthExceeded,
LengthExpected,
LengthMultipleExpected,
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct LengthError {
kind: LengthErrorKind,
length: usize,
index: Option<usize>,
}
impl LengthError {
pub fn new(kind: LengthErrorKind, length: usize) -> LengthError {
LengthError {
kind: kind,
length: length,
index: None,
}
}
pub fn with_index(kind: LengthErrorKind, length: usize, index: usize) -> LengthError {
LengthError {
kind: kind,
length: length,
index: Some(index),
}
}
pub fn length(&self) -> usize {
self.length
}
pub fn index(&self) -> Option<usize> {
self.index
}
}