1use std::error::Error;
2use std::fmt::{Debug, Display, Formatter};
3
4pub type Result<T> = std::result::Result<T, ShapeErrorKind>;
5
6#[derive(Clone, Debug)]
7pub struct ShapeError {
8 kind: Box<ShapeErrorKind>,
9}
10
11
12#[derive(Copy, Clone, Debug)]
13pub enum ShapeErrorKind {
14 Insufficient {
16 require: usize,
18 current: usize,
20 },
21}
22
23impl Error for ShapeError {}
24
25impl Error for ShapeErrorKind {}
26
27impl Display for ShapeError {
28 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
29 Display::fmt(self.kind(), f)
30 }
31}
32
33
34impl Display for ShapeErrorKind {
35 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
36 Debug::fmt(self, f)
37 }
38}
39
40
41impl ShapeError {
42 pub fn kind(&self) -> &ShapeErrorKind {
44 &self.kind
45 }
46
47 pub fn insufficient_points(require: usize, current: usize) -> Self {
49 Self { kind: Box::new(ShapeErrorKind::Insufficient { require, current }) }
50 }
51}