shape-core 0.1.17

Definition of geometry shapes
Documentation
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 number of points.
    Insufficient {
        /// Required number of points.
        require: usize,
        /// Current number of points.
        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 {
    /// Find the error kind
    pub fn kind(&self) -> &ShapeErrorKind {
        &self.kind
    }

    /// Create a new error with insufficient points.
    pub fn insufficient_points(require: usize, current: usize) -> Self {
        Self { kind: Box::new(ShapeErrorKind::Insufficient { require, current }) }
    }
}