1use std::fmt;
2#[cfg(feature="std")]
3use std::any::Any;
4#[cfg(feature="std")]
5use std::error::Error;
6
7#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
9pub struct CapacityError<T = ()> {
10    element: T,
11}
12
13impl<T> CapacityError<T> {
14    pub const fn new(element: T) -> CapacityError<T> {
16        CapacityError {
17            element: element,
18        }
19    }
20
21    pub fn element(self) -> T {
23        self.element
24    }
25
26    pub fn simplify(self) -> CapacityError {
28        CapacityError { element: () }
29    }
30}
31
32const CAPERROR: &'static str = "insufficient capacity";
33
34#[cfg(feature="std")]
35impl<T: Any> Error for CapacityError<T> {}
37
38impl<T> fmt::Display for CapacityError<T> {
39    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
40        write!(f, "{}", CAPERROR)
41    }
42}
43
44impl<T> fmt::Debug for CapacityError<T> {
45    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
46        write!(f, "{}: {}", "CapacityError", CAPERROR)
47    }
48}
49