use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
pub type Result<T> = std::result::Result<T, ShapeErrorKind>;
#[derive(Clone, Debug)]
pub struct ShapeError {
kind: Box<ShapeErrorKind>,
}
#[derive(Copy, Clone, Debug)]
pub enum ShapeErrorKind {
Insufficient {
require: usize,
current: usize,
},
}
impl Error for ShapeError {}
impl Error for ShapeErrorKind {}
impl Display for ShapeError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(self.kind(), f)
}
}
impl Display for ShapeErrorKind {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Debug::fmt(self, f)
}
}
impl ShapeError {
pub fn kind(&self) -> &ShapeErrorKind {
&self.kind
}
pub fn insufficient_points(require: usize, current: usize) -> Self {
Self { kind: Box::new(ShapeErrorKind::Insufficient { require, current }) }
}
}