| David Tolnay | c5a52f9 | 2020-09-14 00:43:29 -0400 | [diff] [blame] | 1 | use alloc::boxed::Box; |
| David Tolnay | 48c01a6 | 2021-04-16 00:25:53 -0700 | [diff] [blame] | 2 | use core::fmt::{self, Display}; |
| David Tolnay | ebef4a2 | 2020-03-17 15:33:47 -0700 | [diff] [blame] | 3 | |
| David Tolnay | c72a9f6 | 2020-11-11 10:56:26 -0800 | [diff] [blame] | 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 { |
| David Tolnay | cb07a84 | 2021-04-16 16:08:52 -0700 | [diff] [blame^] | 19 | #[allow(missing_docs)] |
| David Tolnay | ebef4a2 | 2020-03-17 15:33:47 -0700 | [diff] [blame] | 20 | pub fn what(&self) -> &str { |
| 21 | &self.what |
| 22 | } |
| 23 | } |