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

Add rust::Vec accessors #257

Merged
merged 1 commit into from
Aug 27, 2020
Merged

Add rust::Vec accessors #257

merged 1 commit into from
Aug 27, 2020

Conversation

rinon
Copy link
Contributor

@rinon rinon commented Aug 21, 2020

Adds operator[], at(), front(), and back() to rust::Vec.

This is the read-only accessor side of #149, not sure if we want mutable accessors.

Adds operator[], at(), front(), and back() to rust::Vec.
@rinon
Copy link
Contributor Author

rinon commented Aug 21, 2020

These accessors have the same (un)safety as the corresponding accessor for std::vector. Not sure if we want that, but it's a starting point.

I added no_exceptions checks for at(), which throws in std. AFAICT this is the first thing that should throw. Do you want to support exceptions?

Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is great.

I think matching the (un)safety of the equivalently named std::vector APIs is the right call.

For exceptions, in #92 we had landed on the approach in #101. I am going to make a follow up PR to unify how Vec::at does exceptions with what String's and Str's constructors are doing.

@dtolnay dtolnay merged commit fb8ddd8 into dtolnay:master Aug 27, 2020
@dtolnay
Copy link
Owner

dtolnay commented Aug 27, 2020

not sure if we want mutable accessors.

Yes, I think we do want these!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants