1use core::{
2 cell::{BorrowError, BorrowMutError},
3 error::Error,
4 fmt::{self, Display, Formatter},
5};
6
7#[derive(Debug)]
9pub enum AnyFnError {
10 Borrow(BorrowError),
12 BorrowMut(BorrowMutError),
14 Downcast,
16}
17
18impl From<BorrowError> for AnyFnError {
19 fn from(error: BorrowError) -> Self {
20 Self::Borrow(error)
21 }
22}
23
24impl From<BorrowMutError> for AnyFnError {
25 fn from(error: BorrowMutError) -> Self {
26 Self::BorrowMut(error)
27 }
28}
29
30impl Error for AnyFnError {}
31
32impl Display for AnyFnError {
33 fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
34 match self {
35 Self::Downcast => write!(formatter, "cannot downcast object"),
36 Self::Borrow(error) => write!(formatter, "{error}"),
37 Self::BorrowMut(error) => write!(formatter, "{error}"),
38 }
39 }
40}