-
Notifications
You must be signed in to change notification settings - Fork 246
feat(async-io): make async Write::flush
a required method
#696
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
Conversation
ad2fb51
to
aa3f838
Compare
Write::flush
a required methodWrite::flush
a required method
The only difference between providing a no-op and requiring it is in convenience to an implementer that doesn't buffer (who'd need to just put the empty fn in) and in ensuring everyone thinks about whether they do (making writing the empty impl fn a written statement of "we indeed don't need to flush"). This is not so much a technical but a educational / social question: Do we expect that people who buffer know that they need to implement a flush (because in their write impl, they explicitly chose not to really write), or do we want to rub it in visibly, even at the cost of annoying users who don't do buffering? Personally, whenever I implemented this I wasn't buffering, so I was glad that the no-op is provided (and would even advocate we do the same in the non-async version). That may need some little text in the write docs that cautions against buffering without impl'ing flush. |
I think aligning with According to the crate description, the crate provides traits equivalent to their Also, there are recent precedents to being more restrictive than strictly necessary to align with
This question has been answered by the Rust team as well (rust-lang/rfcs#576 (comment)):
After having researched this a bit more, I think making this a required method would be the right call. Deviating from it would require a good explanation, in my opinion. |
Reviewing that background, I agree that requiring a flush is at least a consistent thing to do. I don't think that embedded devices should generally take the std interfaces verbatim, especially when the standard interfaces follow conventions that have historically grown (in particular, embedded-nal should not look like POSIX sockets), but in this concrete case, consistency is what the crate promises, and this PR provides that consistency here. |
Write::flush
a required methodWrite::flush
a required method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With -async also being up for a 0.7 release, this has entered the critical path of #679 (comment).
The code is pretty self-explanatory, looks correct, and with the emerging consensus that this is the way, repeating my previous ACK in as formal as I can a way here.
aa3f838
to
d75daf9
Compare
I rebased on latest |
This PR makes
embedded-io-async
'sWrite::flush
method a required method, meaning all implementors have to implement it.This aligns this method with
std
'sWrite::flush
andembedded-io
'sWrite::flush
.This PR is more a question than a proposal.
I could not find any documented reasons for the async
flush
being a provided method.If this turns out to be intentional, I am happy to leave it as is and document the reason instead.
CC: @Dirbaio, who added this in the initial design (
d6f6419
).