rust-embedded / embedded-hal

A Hardware Abstraction Layer (HAL) for embedded systems
Apache License 2.0
1.95k stars 197 forks source link

Implement from custom write errors for Infallible #491

Closed rmja closed 1 year ago

rmja commented 1 year ago

This PR will allow io middleware to constrain their Write implementation to a restricted error type that can convert from the new WriteAllError/WriteFmtError types. One example is the proposal over here: https://github.com/rmja/buffered-io/blob/constrained-write-error/src/asynch/write.rs#L28-L30

Specifically, it allows for easy use of e.g. Vec in tests which has the Infallible error type.

For reference, see the discussions here:

And, please, let me know if there is anything obvious that I am missing that could easy the transition to handling these two new error types.

cc @lulf @Dirbaio @MabezDev

Dirbaio commented 1 year ago

an impl Write<Error=Infallible> can still return 0 from write(), which would cause a WriteAllError::WriteZero. So the panics here are not unreachable.

I think it's not idiomatic for From impls to panic. TryFrom would be appropriate here, though that doesn't work with ? which I guess is your goal.

rmja commented 1 year ago

Given the discussion on the previous wg meeting where I believe the consensus was to revert the introduction of the WriteAllError type in favor of disallowing Ok(0) from write(), this PR gets superfluous.