rust-lang / rust-lang/rust-analyzer
New assist: Generate `IndexMut` implementation from `Index` implementation
Open
@Young-Flash is already working on this.
Since Nov 2, 2023.
A-assists
C-feature
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Given an existing core::ops::Index implementation, this assist would generate a copy of it where
IndexbecomesIndexMut- The method signature is updated
&in the return value position in the function body (and perhaps other obviously-relevant positions) is replaced with&mut
For an example from the code I'm working on right now,
pub enum Axis { X = 0, Y = 1, Z = 2 }
impl<T> ops::Index<Axis> for [T; 3] {
type Output = T;
fn index(&self, index: Axis) -> &Self::Output {
&self[index as usize]
}
}
could be used to generate
impl<T> ops::IndexMut<Axis> for [T; 3] {
fn index_mut(&mut self, index: Axis) -> &mut Self::Output {
&mut self[index as usize]
}
}
with no manual changes instead of 6. There might be other ref/mut trait pairs that could be assisted similarly, too.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.