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 clarity to the examples of some Vec & VecDeque methods #134310

Merged
merged 3 commits into from
Dec 15, 2024

Conversation

tkr-sh
Copy link
Contributor

@tkr-sh tkr-sh commented Dec 14, 2024

In some Vec and VecDeque examples where elements are i32, examples can seem a bit confusing at first glance if a parameter of the method is an usize.

In this case, I think it's better to use char rather than i32.

Note

It's already done in the implementation of VecDeque::insert

Difference

  • i32
let mut v = vec![1, 2, 3];
assert_eq!(v.remove(1), 2);
assert_eq!(v, [1, 3]);
  • char
let mut v = vec!['a', 'b', 'c'];
assert_eq!(v.remove(1), 'b');
assert_eq!(v, ['a', 'c']);

Even tho it's pretty minor, it's a nice to have.

@rustbot
Copy link
Collaborator

rustbot commented Dec 14, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Noratrieb (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 14, 2024
@rustbot

This comment has been minimized.

In some `Vec` and `VecDeque` examples where elements are i32, examples can seem a bit confusing at first glance if a parameter of the method is an usize.
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 14, 2024
@tkr-sh
Copy link
Contributor Author

tkr-sh commented Dec 14, 2024

@rustbot label +A-docs

@rustbot rustbot added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Dec 14, 2024
Copy link
Member

@Noratrieb Noratrieb left a comment

Choose a reason for hiding this comment

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

Thanks, I agree that this makes it a lot clearer!

@Noratrieb
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Dec 14, 2024

📌 Commit 6d5c591 has been approved by Noratrieb

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 14, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 15, 2024
Rollup of 7 pull requests

Successful merges:

 - rust-lang#130361 (std::net: Solaris supports `SOCK_CLOEXEC` as well since 11.4.)
 - rust-lang#133406 (Add value accessor methods to `Mutex` and `RwLock`)
 - rust-lang#133633 (don't show the full linker args unless `--verbose` is passed)
 - rust-lang#134285 (Add some convenience helper methods on `hir::Safety`)
 - rust-lang#134310 (Add clarity to the examples of some `Vec` & `VecDeque` methods)
 - rust-lang#134313 (Don't make a def id for `impl_trait_in_bindings`)
 - rust-lang#134315 (A couple of polonius fact generation cleanups)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b974187 into rust-lang:master Dec 15, 2024
6 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Dec 15, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 15, 2024
Rollup merge of rust-lang#134310 - tkr-sh:master, r=Noratrieb

Add clarity to the examples of some `Vec` & `VecDeque` methods

In some `Vec` and `VecDeque` examples where elements are `i32`, examples can seem a bit confusing at first glance if a parameter of the method is an `usize`.

In this case, I think it's better to use `char` rather than `i32`.

> [!NOTE]
> It's already done in the implementation of `VecDeque::insert`

#### Difference

- `i32`
```rs
let mut v = vec![1, 2, 3];
assert_eq!(v.remove(1), 2);
assert_eq!(v, [1, 3]);
```
- `char`
```rs
let mut v = vec!['a', 'b', 'c'];
assert_eq!(v.remove(1), 'b');
assert_eq!(v, ['a', 'c']);
```

Even tho it's pretty minor, it's a nice to have.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants