diff options
| author | Mike Buland <mike@xagasoft.com> | 2026-06-11 10:43:24 -0700 |
|---|---|---|
| committer | Mike Buland <mike@xagasoft.com> | 2026-06-11 10:43:24 -0700 |
| commit | 92dbff3cda66a2a677f0c2306bb8508c64884445 (patch) | |
| tree | e0118f3a4f45b03558b878864c37d33384d736c8 /src/error.rs | |
| parent | 887943e3f1908583d6888c8375f345b33b74fdb5 (diff) | |
| download | crimtag-92dbff3cda66a2a677f0c2306bb8508c64884445.tar.gz crimtag-92dbff3cda66a2a677f0c2306bb8508c64884445.tar.bz2 crimtag-92dbff3cda66a2a677f0c2306bb8508c64884445.tar.xz crimtag-92dbff3cda66a2a677f0c2306bb8508c64884445.zip | |
Broke out error and renamed it.
I like the new name, now it could be for all sorts.
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..a2b6d96 --- /dev/null +++ b/src/error.rs | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | |||
| 2 | use core::error::Error; | ||
| 3 | use std::fmt; | ||
| 4 | |||
| 5 | use crate::position::*; | ||
| 6 | |||
| 7 | #[derive(Debug)] | ||
| 8 | pub struct CrimError { | ||
| 9 | position: Position, | ||
| 10 | what: String, | ||
| 11 | } | ||
| 12 | |||
| 13 | impl CrimError { | ||
| 14 | pub fn new( position: Position, what: String ) -> Self { | ||
| 15 | CrimError { | ||
| 16 | position, | ||
| 17 | what, | ||
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | pub fn eos( context: &str ) -> Self { | ||
| 22 | CrimError { | ||
| 23 | position: Position::none(), | ||
| 24 | what: format!("Premature end of stream while looking for {}", context), | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | pub fn what(&self) -> &str { | ||
| 29 | &self.what | ||
| 30 | } | ||
| 31 | |||
| 32 | pub fn start(&self) -> &Position { | ||
| 33 | &self.position | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | impl fmt::Display for CrimError { | ||
| 38 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| 39 | write!(f, "Error parsing input: {}", "yeah") | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | impl Error for CrimError { } | ||
| 44 | |||
| 45 | pub type CrimResult<T> = Result<T, CrimError>; | ||
