Closed rursprung closed 1 month ago
see #629 for an alternative approach which however doesn't seem to work (but would be much more concise if it did!)
Looks good. Is there an example on how that would be used in practice (in a hal impl and then in e.g. a device driver)?
I would now expect device drivers to impl core::error::Error
for their errors (using e.g. thiserror
) as well with fn source(&self)
wanting to call the hal impl's Some(&hal_impl_error.kind() as &dyn Error)
.
But that ErrorKind
result needs to be kept alive making it a bit inconvenient. I guess they'll need to eagerly call and store the ErrorKind on their creation. Playground.
The full solution appears to be ErrorType::Error: Error + core::error::Error
.
Demanding that from HALs is breaking but it's not difficult to satisfy.
Without that requirement this PR is hard to make use of.
How does the error trait fit with defmt? Is it possible to use it properly while still leveraging the greatness of defmt?
How does the error trait fit with defmt? Is it possible to use it properly while still leveraging the greatness of defmt?
This doesn't take away anything. It only adds the trait. You don't need to use it, so there's nothing getting in the way of defmt
Yeah, I get that. The question was more on whether there is a way to utilize the error trait in a defmt application, or if that would always end up being all device side formatting?
2 weeks have passed and no one from the HAL team has raised concerns, let's merge.
I propose merging but waiting a bit more for release.
this trait has been stabilised in Rust 1.81.0.
the existing custom
Error
types cannot be removed / replaced as that'd be a breaking change. for the same reason it's not possible for them to requirecore::error::Error
being implemented.however, we can already implement the new trait for all cases where the custom trait has been implemented so far.
existing
std
feature-gated implementations ofstd::error::Error
have also been moved tocore::error::Error
and the feature gate removed.this raises the MSRV to 1.81.0 for most crates, but based on the MSRV policy this should not be an issue.