Skip to content

Implement Index<usize> and IndexMut<usize> for Deque - #697

Open
mikwielgus wants to merge 1 commit into
rust-embedded:mainfrom
mikwielgus:index-index-mut-for-vecdeque
Open

mikwielgus wants to merge 1 commit into
rust-embedded:mainfrom
mikwielgus:index-index-mut-for-vecdeque

Conversation

@mikwielgus

Copy link
Copy Markdown
Contributor

This continues f70f19c.

This is consistent with standard library's VecDeque, which also has Index<usize> and IndexMut<usize> implemented.

This continues f70f19c.

This is consistent with standard library's `VecDeque`, which also has
`Index<usize>` and `IndexMut<usize>` implemented.
@mikwielgus
mikwielgus force-pushed the index-index-mut-for-vecdeque branch from 4cd0cc8 to c297961 Compare November 3, 2026 20:54

@sgued sgued left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

The implementation looks good to me, just one nit regarding the tests.

Comment thread src/deque.rs
Comment on lines +1900 to +1916
fn increment<C>(container: &mut C, index: usize)
where
C: std::ops::IndexMut<usize>,
C::Output: std::ops::AddAssign<i32>,
{
container[index] += 1;
}

increment(&mut q, 1);
assert_eq!(q[1], 10);

fn get<C>(container: &C, index: usize) -> &<C as core::ops::Index<usize>>::Output
where
C: std::ops::Index<usize>,
{
&container[index]
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deque doesn't implement deref, so I don't think the added function is necessary to make sure the right implementation is tested.

This branch has not been deployed

No deployments
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