Repository navigation
io: add get_{ref,mut} methods to AsyncFdReadyGuard and AsyncFdReadyMutGuard. - #3807
Merged
Merged
Conversation
…tGuard. The only way to use AsyncFdReadyMutGuard currently is through try_io, since it is impossible to access the underlying object. In some situations, it is desirable to use clear_ready and retain_ready directly instead of try_io. Enable this by adding get_ref and get_mut methods.
Member
|
One option is to also add an |
Contributor
Author
|
Yes. So, would you rather see four methods I personally doubt that accessing the |
Member
|
We can add all four. Even if it isn't very useful right now, it might get new methods in the future where it is useful. |
Darksonn
reviewed
May 26, 2021
Comment on lines
+483
to
+491
| /// Returns a shared reference to the inner [`AsyncFd`]. | ||
| pub fn get_ref(&self) -> &AsyncFd<Inner> { | ||
| self.async_fd | ||
| } | ||
|
|
||
| /// Returns a shared reference to the backing object of the inner [`AsyncFd`]. | ||
| pub fn get_inner(&self) -> &Inner { | ||
| self.get_ref().get_ref() | ||
| } |
Member
There was a problem hiding this comment.
Can you move the methods to the bottom of the impl block so they don't appear at the top of the documentation?
…m of the impl block.
Darksonn
approved these changes
May 27, 2021
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The only way to use
AsyncFdReadyMutGuardcurrently is throughtry_io, since it is impossible to access the underlying object. In some situations, it is desirable to useclear_readyandretain_readydirectly instead oftry_io. Enable this by addingget_refandget_mutmethods.Motivation
When using
AsyncFdwith an I/O object that does not communicate readiness throughErrorKind::WouldBlock, code usingtry_iobecomes hard to read. In the following example, thenext()method returnsNonewhen no new data is ready.As seen here, you have to explicitly convert
Noneto aWouldBlockerror intry_io, only to convert that error back intoPendingafterwards. This is confusing to read.Solution
By adding
AsyncFdReadyMutGuard::get_mut, this can be expressed in a more straight-forward way:The
get_refmethods are added for consistency.Questions
Should we return a reference to
AsyncFd<T>orT?try_iousesAsyncFd<T>in its argument, so the proposed solution is consistent. On the other hand, in probably all cases, this requires writingguard.get_mut().get_mut().