1515//! Errors at the application shell level.
1616
1717use std:: fmt;
18+ use std:: sync:: Arc ;
1819
1920use crate :: platform:: error as platform;
2021
@@ -25,12 +26,10 @@ pub enum Error {
2526 ApplicationAlreadyExists ,
2627 /// The window has already been destroyed.
2728 WindowDropped ,
28- /// Runtime borrow failure.
29- BorrowError ( BorrowError ) ,
3029 /// Platform specific error.
3130 Platform ( platform:: Error ) ,
3231 /// Other miscellaneous error.
33- Other ( & ' static str ) ,
32+ Other ( Arc < anyhow :: Error > ) ,
3433}
3534
3635impl fmt:: Display for Error {
@@ -39,64 +38,23 @@ impl fmt::Display for Error {
3938 Error :: ApplicationAlreadyExists => {
4039 write ! ( f, "An application instance has already been created." )
4140 }
42- Error :: WindowDropped => write ! ( f, "The window has already been destroyed." ) ,
43- Error :: BorrowError ( err) => fmt:: Display :: fmt ( err, f) ,
4441 Error :: Platform ( err) => fmt:: Display :: fmt ( err, f) ,
42+ Error :: WindowDropped => write ! ( f, "The window has already been destroyed." ) ,
4543 Error :: Other ( s) => write ! ( f, "{}" , s) ,
4644 }
4745 }
4846}
4947
5048impl std:: error:: Error for Error { }
5149
52- impl From < platform :: Error > for Error {
53- fn from ( src : platform :: Error ) -> Error {
54- Error :: Platform ( src)
50+ impl From < anyhow :: Error > for Error {
51+ fn from ( src : anyhow :: Error ) -> Error {
52+ Error :: Other ( Arc :: new ( src) )
5553 }
5654}
5755
58- /// Runtime borrow failure.
59- #[ derive( Debug , Clone ) ]
60- pub struct BorrowError {
61- location : & ' static str ,
62- target : & ' static str ,
63- mutable : bool ,
64- }
65-
66- impl BorrowError {
67- pub fn new ( location : & ' static str , target : & ' static str , mutable : bool ) -> BorrowError {
68- BorrowError {
69- location,
70- target,
71- mutable,
72- }
73- }
74- }
75-
76- impl fmt:: Display for BorrowError {
77- fn fmt ( & self , f : & mut fmt:: Formatter ) -> Result < ( ) , fmt:: Error > {
78- if self . mutable {
79- // Mutable borrow fails when any borrow exists
80- write ! (
81- f,
82- "{} was already borrowed in {}" ,
83- self . target, self . location
84- )
85- } else {
86- // Regular borrow fails when a mutable borrow exists
87- write ! (
88- f,
89- "{} was already mutably borrowed in {}" ,
90- self . target, self . location
91- )
92- }
93- }
94- }
95-
96- impl std:: error:: Error for BorrowError { }
97-
98- impl From < BorrowError > for Error {
99- fn from ( src : BorrowError ) -> Error {
100- Error :: BorrowError ( src)
56+ impl From < platform:: Error > for Error {
57+ fn from ( src : platform:: Error ) -> Error {
58+ Error :: Platform ( src)
10159 }
10260}
0 commit comments