-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation #4
Comments
Some random bits I think might be worth addressing (though not sure if it makes more sense for docs, or a blog, or):
I really like the readme so far, and the doc comments too! The only part that I feel is absent still is examples, in particular some common patterns. And some of the context around Fehler and the Rust language. |
I thought this pattern was really nice, but I don't know if anyone has ever actually used it! |
I used to for the longest time, but it ended up being a lot of boilerplate that I eventually stopped using it. I do feel like it represents the right pattern, and wish it was easier to construct! |
It's very easy to wipe away the boilerplate. Pretty sure if the user just defines error_with_kind! { MyError => MyErrorKind }
// Do this part yourself
enum MyErrorKind {
// ...
} But I've never really liked these gadgetty macros that create a whole type with a bunch of different impls. |
Yeah, I never liked those macros either. I was wondering though; since // The "Error" type is provided by Der Fehler, which we can reuse in our type alias.
mod fehler {
use std::fmt::{self, Debug, Display};
pub struct Error<E: Display> {
inner: E
}
impl<E: Display> Display for Error<E> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Display::fmt(&self.inner, f)
}
}
impl<E: Display> Debug for Error<E> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Display::fmt(self, f)
}
}
impl<E: Display> std::error::Error for Error<E> {}
}
/// The kinds of errors that can occur.
#[derive(Debug, Display)]
pub enum ErrorKind {
/// The user id {user_id} is invalid
UserIdInvalid { user_id: i32 },
/// An error not part of this list
Other,
}
/// Our crate's error kind
pub type Error = fehler::Error<ErrorKind>; This would have the downside of not neatly showing up as a struct in the docs. But neither do I have the feeling I might be missing something, but perhaps this may actually be an option? |
That's exactly what failure's |
Ahh, okay! I thought I was onto something, haha. |
Please add |
I cannot find in the documentation how it behaves with |
Maybe a bit late, but I would share my experience. For example: #[derive(From, Debug, Display)]
enum MyError {
#[display(fmt = "IO Error: {}", _0)]
Io(std::io::Error),
#[display(fmt = "Format Error: {}", _0)]
Format(std::fmt::Error)
}
impl std::error::Error for MyError {}; With |
When I want a more generic error type I use |
Would be nice to have actually good documentation here
The text was updated successfully, but these errors were encountered: