-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Use Try
trait to make Once[Cell | Lock]::get_or_try_init
generic over return type
#107122
base: master
Are you sure you want to change the base?
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
With this approach, IFAICT and judging from the development around |
{ | ||
let mut res: Result<(), E> = Ok(()); |
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.
Might make sense to check for other uses of res
in the relevant files, as that’s the name I use a lot.
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.
There is one other case in Clone
, but I think it's fine as is. I just don't want to use res
here since it could cause confusion as to whether it means "result" or "residual".
@scottmcm I'm assuming this looks good to you? Assigning it to someone from libs-api for their approval... r? libs-api |
I'm not sure how I feel about this. The type signature here is really unwieldy. But I suppose that will be a problem for any API that is generic over |
I'd say From a syntax point of view, having to specify the result type explicitly is very unlikely as just using |
My mind's eye sees it as less "restrictive" and more "less convenient." If you really do want to return an |
☔ The latest upstream changes (presumably #105587) made this pull request unmergeable. Please resolve the merge conflicts. |
In any case, this seems to need a rebase. |
0a0b0ee
to
db38c59
Compare
@rustbot ready |
☔ The latest upstream changes (presumably #114272) made this pull request unmergeable. Please resolve the merge conflicts. |
I think this is blocked on a team decision on the proper design of the @rustbot label +S-blocked -S-waiting-on-author |
We discussed this in the libs-api meeting today. Any APIs that could make use of |
db38c59
to
570f593
Compare
This comment was marked as outdated.
This comment was marked as outdated.
570f593
to
9b1c7b9
Compare
Sorry, made an error while rebasing. |
I don't think I'm fully on board with this personally. Or at the very least, I'm pretty unhappy with where we've ended up. The difference in type signature complexity is pretty wild, and it isn't totally clear to me that the complexity is buying us much. Compare the status quo:
With
I find this signature very difficult to read personally. And using this for the basic case of returning a I think we are in a tough spot. I don't really know what to do here:
I am very conflicted on what to do here. But I am very unhappy with type signatures that look like this when the 99% use case would be serviced by something more concrete. |
To me, the one important purpose of |
This came up in the stabilization PR: #105587 (comment)
Using
Try
allows these methods to accept types likeOption
in cases where there is no applicable error type.@rustbot label +T-libs-api +T-libs
r? @scottmcm