Skip to content

[io] Require static lifetime bound on Error#731

Open
Conaclos wants to merge 1 commit intorust-embedded:masterfrom
Conaclos:conaclos/error-static-bound
Open

[io] Require static lifetime bound on Error#731
Conaclos wants to merge 1 commit intorust-embedded:masterfrom
Conaclos:conaclos/error-static-bound

Conversation

@Conaclos
Copy link
Contributor

@Conaclos Conaclos commented Mar 24, 2026

This PR requires types that implement embedded_io::Error to have a static lifetime.
This is a breaking change. However, this should not widely impact the ecosystem because most of the error types are static anyway.

Why this change?
This is basically the same rationales as d02f6db
Many crates require error types to implement core::error::Error and to be 'static.
One of the reason is because of core::error::Error::source that returns a dyn core::error::Error +'static.

Working with these crates and embedded-io makes things hard because you have to constraint the Error associated type on every generic functions.
Here is an example:

fn f<R: embedded_io::Read>(r: &mut R) -> Result<(), a_crate::Error<R::Error>>
where R::Error: 'static {}

Requiring 'static on embedded_io::Error makes things less tedious.
Moreover, it is considered as a best practice in the Rust community of requiring both core::error::Error and 'static on Error types.

I didn't make the change on other crates because their Error types don't implement core::error::Error (yet?).

@Conaclos Conaclos requested a review from a team as a code owner March 24, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant