| David Tolnay | c5a52f9 | 2020-09-14 00:43:29 -0400 | [diff] [blame] | 1 | use alloc::boxed::Box; |
| David Tolnay | 3384c14 | 2020-09-14 00:26:47 -0400 | [diff] [blame] | 2 | use core::fmt::{self, Debug, Display}; |
| David Tolnay | ebef4a2 | 2020-03-17 15:33:47 -0700 | [diff] [blame] | 3 | |
| 4 | /// Exception thrown from an `extern "C"` function. |
| David Tolnay | eedf737 | 2020-05-22 11:08:50 -0700 | [diff] [blame] | 5 | #[derive(Debug)] |
| David Tolnay | ebef4a2 | 2020-03-17 15:33:47 -0700 | [diff] [blame] | 6 | pub struct Exception { |
| 7 | pub(crate) what: Box<str>, |
| 8 | } |
| 9 | |
| 10 | impl Display for Exception { |
| 11 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 12 | f.write_str(&self.what) |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | impl std::error::Error for Exception {} |
| 17 | |
| 18 | impl Exception { |
| 19 | pub fn what(&self) -> &str { |
| 20 | &self.what |
| 21 | } |
| 22 | } |