tighterror/error.rs
1use crate::{Category, Kind, Location};
2use core::fmt::{Debug, Display};
3
4/// The trait of error types.
5///
6/// See the crate documentation for more information.
7pub trait Error: Debug + Display {
8 /// The underlying Rust type of error kind.
9 ///
10 /// A concrete builtin type, e.g., `u8`.
11 type R;
12
13 /// The error category concrete type.
14 type Category: Category<R = Self::R>;
15
16 /// The error kind concrete type.
17 type Kind: Kind<R = Self::R, Category = Self::Category>;
18
19 /// Returns the error kind.
20 ///
21 /// The error kind is unique per `tighterror::Error` instantiation.
22 fn kind(&self) -> Self::Kind;
23
24 /// Returns the error category.
25 ///
26 /// This method is a shorthand for `self.kind().category()`.
27 #[inline]
28 fn category(&self) -> Self::Category {
29 self.kind().category()
30 }
31
32 /// Returns the error's source location.
33 ///
34 /// By default an *undefined* location is returned, unless the
35 /// concrete error type supports it and the error instance is initialized
36 /// with it.
37 fn location(&self) -> Location {
38 Location::undefined()
39 }
40}