Here it is. erratic.
Since I keep running into binary projects where errors need to be handled differently by type, designing error types for every module has really been giving me a headache.
So I ended up making an error type Error<S = Stateless>, a bit like Box<dyn Error>, but with a generic parameter attached. That generic can be any type that implements Debug (mostly an enum), and it's used to mark the error state (like ErrorKind) that need to be handled by the upper layers.
Then I also applied a small trick: Making Stateless: ?Sized. That way From<Error> for Error<S> satisfies coherence, and propagating errors with ? becomes really convenient. It gives you a bit of orthogonality: once an error you don't care about is erased, you can just ignore the State type entirely and keep bubbling it up.
The efficiency is... not too bad, I think? It's only 1 usize in size. If the error is constructed from a string literal, it costs almost as little as &'static str. If it comes from a state type smaller than 1 usize (given that its alignment fits), it avoids allocation altogether. And in other cases does it actually allocate.
I've been tinkering with this for a few months now. English isn't my first language, so the naming and docs are a bit rough around the edges. Any advice or suggestions would mean a lot to me, especially on the naming and docs. ![]()
![]()
![]()
Edit: This splash is written in Typst, and the positioning is automatically calculated. Feel free to edit the script to make one for your own crate!
