Skip to content

Commit

Permalink
Replace i32 by char to add clarity
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tkr-sh authored and gitbot committed Feb 20, 2025
1 parent 433ec5e commit cb38349
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
21 changes: 12 additions & 9 deletions alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
///
/// vec_deque.insert(1, 'd');
/// assert_eq!(vec_deque, &['a', 'd', 'b', 'c']);
///
/// vec_deque.insert(4, 'e');
/// assert_eq!(vec_deque, &['a', 'd', 'b', 'c', 'e']);
/// ```
#[stable(feature = "deque_extras_15", since = "1.5.0")]
#[track_caller]
Expand Down Expand Up @@ -1928,13 +1931,13 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// use std::collections::VecDeque;
///
/// let mut buf = VecDeque::new();
/// buf.push_back(1);
/// buf.push_back(2);
/// buf.push_back(3);
/// assert_eq!(buf, [1, 2, 3]);
/// buf.push_back('a');
/// buf.push_back('b');
/// buf.push_back('c');
/// assert_eq!(buf, ['a', 'b', 'c']);
///
/// assert_eq!(buf.remove(1), Some(2));
/// assert_eq!(buf, [1, 3]);
/// assert_eq!(buf.remove(1), Some('b'));
/// assert_eq!(buf, ['a', 'c']);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_confusables("delete", "take")]
Expand Down Expand Up @@ -1982,10 +1985,10 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// ```
/// use std::collections::VecDeque;
///
/// let mut buf: VecDeque<_> = [1, 2, 3].into();
/// let mut buf: VecDeque<_> = ['a', 'b', 'c'].into();
/// let buf2 = buf.split_off(1);
/// assert_eq!(buf, [1]);
/// assert_eq!(buf2, [2, 3]);
/// assert_eq!(buf, ['a']);
/// assert_eq!(buf2, ['b', 'c']);
/// ```
#[inline]
#[must_use = "use `.truncate()` if you don't need the other half"]
Expand Down
28 changes: 14 additions & 14 deletions alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1953,11 +1953,11 @@ impl<T, A: Allocator> Vec<T, A> {
/// # Examples
///
/// ```
/// let mut vec = vec![1, 2, 3];
/// vec.insert(1, 4);
/// assert_eq!(vec, [1, 4, 2, 3]);
/// vec.insert(4, 5);
/// assert_eq!(vec, [1, 4, 2, 3, 5]);
/// let mut vec = vec!['a', 'b', 'c'];
/// vec.insert(1, 'd');
/// assert_eq!(vec, ['a', 'd', 'b', 'c']);
/// vec.insert(4, 'e');
/// assert_eq!(vec, ['a', 'd', 'b', 'c', 'e']);
/// ```
///
/// # Time complexity
Expand Down Expand Up @@ -2024,9 +2024,9 @@ impl<T, A: Allocator> Vec<T, A> {
/// # Examples
///
/// ```
/// let mut v = vec![1, 2, 3];
/// assert_eq!(v.remove(1), 2);
/// assert_eq!(v, [1, 3]);
/// let mut v = vec!['a', 'b', 'c'];
/// assert_eq!(v.remove(1), 'b');
/// assert_eq!(v, ['a', 'c']);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[track_caller]
Expand Down Expand Up @@ -2715,10 +2715,10 @@ impl<T, A: Allocator> Vec<T, A> {
/// # Examples
///
/// ```
/// let mut vec = vec![1, 2, 3];
/// let mut vec = vec!['a', 'b', 'c'];
/// let vec2 = vec.split_off(1);
/// assert_eq!(vec, [1]);
/// assert_eq!(vec2, [2, 3]);
/// assert_eq!(vec, ['a']);
/// assert_eq!(vec2, ['b', 'c']);
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]
Expand Down Expand Up @@ -2982,9 +2982,9 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
/// vec.resize(3, "world");
/// assert_eq!(vec, ["hello", "world", "world"]);
///
/// let mut vec = vec![1, 2, 3, 4];
/// vec.resize(2, 0);
/// assert_eq!(vec, [1, 2]);
/// let mut vec = vec!['a', 'b', 'c', 'd'];
/// vec.resize(2, '_');
/// assert_eq!(vec, ['a', 'b']);
/// ```
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "vec_resize", since = "1.5.0")]
Expand Down

0 comments on commit cb38349

Please sign in to comment.