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

Improve the example for Vec::splice #92067

Closed
ajtribick opened this issue Dec 18, 2021 · 1 comment · Fixed by #92071
Closed

Improve the example for Vec::splice #92067

ajtribick opened this issue Dec 18, 2021 · 1 comment · Fixed by #92071

Comments

@ajtribick
Copy link
Contributor

The current example for Vec::splice illustrates the replacement of a section of length 2 with a new section of length 2. This isn't a particularly interesting case for splice, and makes it look a bit like a shorthand for the kind of manipulations that could be done with a mutable slice.

I think it would be more useful to illustrate this method with a case where the source and replacement are different lengths, e.g.

let mut v = vec![1, 2, 3, 4];
let new = [7, 8, 9];
let u: Vec<_> = v.splice(1..3, new).collect();
assert_eq!(v, &[1, 7, 8, 9, 4]);
assert_eq!(u, &[2, 3]);

Thoughts?

@jyn514
Copy link
Member

jyn514 commented Dec 18, 2021

@ajtribick seems like a good change :) are you interested in making a PR? This example lives somewhere in library/alloc I think.

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 a pull request may close this issue.

2 participants