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