1use std::error::Error;
2use std::fmt;
3use std::fmt::{Debug, Display};
4
5#[derive(Debug)]
6pub enum ECSError {
7 Borrow,
8 BorrowMut,
9 Downcast,
10 DowncastMut,
11 PtrRef,
12 PtrMut,
13 NoComponentMap,
14 NoComponentForEntity,
15 WithAfterFinalise,
16 FinaliseNonEntity,
17 BitMasksExhausted,
18 AddDupeComponent,
19}
20
21impl Display for ECSError {
22 #[inline]
23 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24 match self {
25 ECSError::Borrow => Display::fmt("already borrowed", f),
26 ECSError::BorrowMut => Display::fmt("already mutably borrowed", f),
27 ECSError::Downcast => Display::fmt("could not downcast to ref", f),
28 ECSError::DowncastMut => Display::fmt("could not downcast to mut ref", f),
29 ECSError::PtrRef => Display::fmt("failed to convert pointer to ref", f),
30 ECSError::PtrMut => Display::fmt("failed to convert pointer to mut", f),
31 ECSError::NoComponentMap => Display::fmt("no component map for type", f),
32 ECSError::NoComponentForEntity => {
33 Display::fmt("part map does not contain part for entity", f)
34 }
35 ECSError::WithAfterFinalise => Display::fmt("use of .with() after .finalise()", f),
36 ECSError::FinaliseNonEntity => {
37 Display::fmt("can not finalise() without new_entity()", f)
38 }
39 ECSError::BitMasksExhausted => {
40 Display::fmt("bitmasks exhausted, can't add new component type", f)
41 }
42 ECSError::AddDupeComponent => {
43 Display::fmt("attempted to add duplicate component to entity", f)
44 }
45 }
46 }
47}
48
49impl Error for ECSError {}