summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2026-06-11 10:43:24 -0700
committerMike Buland <mike@xagasoft.com>2026-06-11 10:43:24 -0700
commit92dbff3cda66a2a677f0c2306bb8508c64884445 (patch)
treee0118f3a4f45b03558b878864c37d33384d736c8 /src/error.rs
parent887943e3f1908583d6888c8375f345b33b74fdb5 (diff)
downloadcrimtag-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.rs45
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
2use core::error::Error;
3use std::fmt;
4
5use crate::position::*;
6
7#[derive(Debug)]
8pub struct CrimError {
9 position: Position,
10 what: String,
11}
12
13impl 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
37impl fmt::Display for CrimError {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 write!(f, "Error parsing input: {}", "yeah")
40 }
41}
42
43impl Error for CrimError { }
44
45pub type CrimResult<T> = Result<T, CrimError>;