Skip to content
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

digital: enforce all traits have the same Error type. #338

Merged
merged 1 commit into from
Jan 12, 2022

Conversation

Dirbaio
Copy link
Member

@Dirbaio Dirbaio commented Dec 20, 2021

Equivalent of #331 for GPIO traits.

This one is a bit trickier, so it maybe warrants some discussion (this is the reason I've opened everything as separate PR's, sorry for the spam!):

  • The bounds on IoPin are becoming very cursed, but I think they're correct... Is there some HAL out there implementing it, so that I can verify this doesn't break it?
  • This forces the "input" and "output" errors to be the same. Perhaps we want to only unify Output and Input separately? In practice I don't think this will be an issue, as structs usually impl only Input or Output but not both (except with IoPin maybe?)

@Dirbaio Dirbaio requested a review from a team as a code owner December 20, 2021 22:21
@rust-highfive
Copy link

r? @therealprof

(rust-highfive has picked a reviewer for you, use r? to override)

@burrbull
Copy link
Member

  • The bounds on IoPin are becoming very cursed, but I think they're correct... Is there some HAL out there implementing it, so that I can verify this doesn't break it?

https://github.com/stm32-rs/stm32f4xx-hal/blob/dc1552b2fc2e14901203a13ab42e76a5121a08eb/src/gpio.rs#L574

@Dirbaio
Copy link
Member Author

Dirbaio commented Dec 21, 2021

Thanks for the link @burrbull . It seems the bounds are OK, the obvious changes worked with no fuss! Dirbaio/stm32f4xx-hal@091d945

eldruin
eldruin previously approved these changes Dec 21, 2021
Copy link
Member

@eldruin eldruin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems correct to me, thanks!
Breaking up the unified error type requirement for IoPin in the future would be a non-breaking change, right?
Iff so, this is fine as-is I would say.

@Dirbaio
Copy link
Member Author

Dirbaio commented Dec 21, 2021

Breaking up the unified error type requirement for IoPin in the future would be a non-breaking change, right?

I have no idea to be honest. Removing the ErrorType bounds on TInput/TOutput seems like it could break consumers relying on it, so it's maybe breaking...?

@eldruin
Copy link
Member

eldruin commented Dec 21, 2021

Breaking up the unified error type requirement for IoPin in the future would be a non-breaking change, right?

I have no idea to be honest. Removing the ErrorType bounds on TInput/TOutput seems like it could break consumers relying on it, so it's maybe breaking...?

Hmm, I see.
There might be an IoPin impl wanting to define a different error type. Something like:

enum IoPinError {
  Input(...),
  Output(...),
  FailedToChangeMode
}

Given this, I would tend not to unify the error type for IoPin.

@Dirbaio
Copy link
Member Author

Dirbaio commented Jan 2, 2022

Changed to leave IoPin alone.

Anyway IMO IoPin requires a redesign.

  • It's incredibly unwieldy to impl IoPin trait not practical to implement with multiple input/output types #340
  • It's incredibly unwieldy to use: you can't simply own one in a driver struct, because every time you use it it changes type. Tshi forces you to store Options or enums and constantly .take()ing it out and putting it back, which results in panicky code with lots of runtime checks.
  • There's still no way to switch between PullUp/PullDown/NoPull, and PushPull/OpenDrain
  • There's no way to impl it in HALs without typestates (such as Embassy). It'd be impl<T: Pin> IoPin<Input<T>, Output<T>> for Blah, but there's not enough info in the type signature to know if you want PushPull or OpenDrain when you switch from Input to Output. Embassy won't impl IoPin.

but that's a different story I guess...

@eldruin
Copy link
Member

eldruin commented Jan 3, 2022

Hmm, I still see IoPin inherit from ErrorType, though.
Could you add that criticism of IoPin to #340?
Have you read through the original discussion at #29?

@Dirbaio Dirbaio force-pushed the digital-unify-error branch from 32a3ed4 to 17b5b70 Compare January 3, 2022 08:02
@Dirbaio
Copy link
Member Author

Dirbaio commented Jan 3, 2022

I screwed up the rebase somehow, it's OK now

@Dirbaio
Copy link
Member Author

Dirbaio commented Jan 11, 2022

Friendly ping @eldruin @therealprof @ryankurte are there any pending concerns on this now that IoPin is left untouched?

Copy link
Contributor

@therealprof therealprof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

bors r+

@bors bors bot merged commit bae5bcb into rust-embedded:master Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Review is incomplete T-hal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants