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

[RFC] blocking/serial: make method naming consistent #280

Merged
merged 2 commits into from Jun 29, 2021

Conversation

Dirbaio
Copy link
Member

@Dirbaio Dirbaio commented May 28, 2021

blocking::serial::Write's methods are named bwrite_all and bflush.

  • the b prefix indicates blocking (I guess?). However no other blocking trait method has this prefix.
  • the _all suffix indicates it writes a slice instead of a single word (I guess?). However, no other trait method that writes a slice has this suffix.

To make them consistent, this PR renames them to write and flush.

@Dirbaio Dirbaio requested a review from a team as a code owner May 28, 2021 21:53
@rust-highfive
Copy link

r? @eldruin

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

@eldruin
Copy link
Member

eldruin commented May 29, 2021

For completeness, as I highlighted in #281, different method names ensure unequivocal selection between different traits when they are all pulled in by the prelude.

  • dev.read() -> nb::serial::Read::read()
  • dev.write() -> nb::serial::Write::write()
  • dev.flush() -> nb::serial::Write::flush()
  • dev.bwrite_all() -> blocking::serial::Write::bwrite_all()
  • dev.bflush() -> blocking::serial::Write::bflush()

The method names can certainly be improved, though. Removing the prelude is also an option.
With the same method names users need to either stop using the prelude or turbofish calls.

@ryankurte
Copy link
Contributor

the blocking/non-blocking delineation makes more sense than the send/write difference to me, i suppose we could also split the prelude for blocking/non-blocking/futures?

@Dirbaio
Copy link
Member Author

Dirbaio commented May 30, 2021

the blocking/non-blocking delineation makes more sense than the send/write difference to me,

Agreed, but then all blocking methods should have the b prefix, not just UART. Or all the nb methods should have the nb_ prefix.

i suppose we could also split the prelude for blocking/non-blocking/futures?

That won't work nicely because people end up using both blocking and nb traits in the same mod. Especially since some traits are only available in blocking flavor and others only in nonblocking flavor.

Nobody uses the same trait in both blocking and nonblocking flavors at the same time though. IMO naming blocking and nonblocking the same is not that bad.

@Dirbaio Dirbaio mentioned this pull request Jun 15, 2021
eldruin
eldruin previously approved these changes Jun 15, 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.

Looks good to me, thanks!

@Dirbaio
Copy link
Member Author

Dirbaio commented Jun 22, 2021

ping @ryankurte @therealprof is there anything missing to get this in? also for #282

therealprof
therealprof previously approved these changes Jun 29, 2021
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, bors r+

@therealprof
Copy link
Contributor

bors r-

@therealprof
Copy link
Contributor

Should have a CHANGELOG.md entry.

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 now, thanks.

bors r+

@bors bors bot merged commit 0ab50cd into rust-embedded:master Jun 29, 2021
bors bot added a commit that referenced this pull request Jun 29, 2021
282: Remove prelude. r=therealprof a=Dirbaio

**DEPENDS on #280**

Following discussions in #280 #281, we might want to use the same method names for the `blocking` and `nb` (and in the future, `futures`) trait flavors.

In that case, importing the prelude guarantees naming conflicts, so it's better to remove it.

An alternative would be splitting the prelude in `blocking` and `nb`. However, users often use blocking trait A and nonblocking trait B at the same time, so they'd end up importing both preludes and having name conflicts anyway.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
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.

None yet

5 participants