-
Notifications
You must be signed in to change notification settings - Fork 229
Change list get
methods to return an Option<T>
#284
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
I suppose we could closely mirror the
Existing I would want to roll this out as a multi-step process, where first we add This would cause some disruption to downstream users, but maybe it's worth it in the long run? |
Makes sense to me.
Yes, I think exactly the same concerns about out-of-bounds and panicking apply there too. |
Alternatively, we could keep the current
This would have the advantage of not disrupting any current users. Appending a capnproto-rust/capnp/src/serialize.rs Lines 266 to 288 in ec84c7a
I'm not too worried about |
@dwrensha what do you prefer? Both approaches seem good to me. My main desire is to have a get-like function that does not panic. I personally think that introducing |
Opened #285 for the |
Yeah |
Added some documentation: da7a9f7 |
Closing in favor of #285. Please open a new pull request if you want to add |
Hi @dwrensha
I have opened this as a draft because its a work-in-progress and I have a few questions but I would like to start the discussion:
I have changed (some)
get
list reader methods to return anOption<T>
and introduced aget_unchecked
to mirror std slice API. This is a breaking change but as far as I know, the API is not considered stable at this point? I think that's the right call because its less confusing since it adhere to idiomatic rust practices but if the change is considered to severe, maybe adding achecked_get
method instead would be more acceptable? A bonus point from this work is that in places where the index is already known to be in range, we can useget_unchecked
directly and avoid some useless bound checks.There are some
get
methods that already return aResult<T>
but usually the index access is done prior to the call that returns the Result. In such case I believe the correct return type would beOption<Result<T>>
. Do you agree?What about
get
builder methods, should they be changed too for coherency?Fixes #251