Crates.io | goof |
lib.rs | goof |
version | 0.2.3 |
source | src |
created_at | 2023-10-26 23:16:15.807245 |
updated_at | 2023-10-31 15:06:08.5514 |
description | A reusable, composable, aggregate and `no_std`-friendly error library |
homepage | |
repository | https://github.com/appetrosyan/goof |
max_upload_size | |
id | 1015396 |
size | 17,063 |
An early composable, and re-usable library for tiny structs that you would be writing on your own, but which you really shouldn't.
use goof::{Mismatch, assert_eq};
fn fallible_func(thing: &[u8]) -> Result<(), Mismatch<usize>> {
assert_eq(&32, &thing.len())?;
Ok(())
}
assert_eq!(fallible_func(&[]).unwrap_err(), assert_eq(&32, &0).unwrap_err())
So why use it? It's pre-alpha, so it's not particularly useful yet.
But imagine a situation in which you don't really want to panic on
failed assertions. These functions can then be a lightweight 1-1
replacement of the standard library `asserteq!` macro. It will not
panic immediately, but instead create a structure called
rustsrc{Mismatch}, which has all of the appropriate traits (except
std::error::Error
{.verbatim} because I want to add std
{.verbatim}
support, rather than subtract it) implemented.
These will participate in all manner of goodies, that don't necessarily
depend on std
{.verbatim}, but that can effectively make
goof
{.verbatim} a one-stop-shop for all your error handling needs. It
will hopefully be as useful as eyre
{.verbatim} and
thiserror
{.verbatim} while providing a slightly different approach to
designing error APIs.
no_std
{.verbatim} compatible. The structures should be easy to
use across the FFI boundary, simple and hopefully predictable in
their behaviours.Copy
{.verbatim}-able if possible.failure
{.verbatim}
crate.
eyre
{.verbatim}, and (hopefully) like in
miette
{.verbatim}.The library is in its early stages. I'm planning on approaching this
from the minimalist perspective, of making a bunch of 0.*
{.verbatim}
versions and when the library is complete, releasing the
1.0
{.verbatim} version. While this is in no way a pre-release
candidate and as is, it should be ready for production use, I would
recommend not spending too much time worrying about the changes in the
newer versions. Update as you see fit, if you do, I will be providing
detailed notes on how to make the jump.
Mismatch
{.verbatim}, Outside
{.verbatim} and
Unknown
{.verbatim} structures.assert_eq
{.verbatim},
assert_in
{.verbatim}, assert_known_enum
{.verbatim}, and
assert_known
{.verbatim}.assert_eq
{.verbatim} for more
consistency.