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 documentation of slicing methods. #989

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cassiersg
Copy link
Contributor

No description provided.

@jturner314
Copy link
Member

jturner314 commented Apr 30, 2021

Thanks for suggesting improvements to the docs.

It's somewhat awkward to reference a few other slicing methods without listing all of the potentially relevant ones. However, I don't think we should list all of them, since there are a lot of slicing methods, and they're all mentioned in the Slicing docs already.

What I'd suggest is to address the question in #988 more directly, i.e. add something like the following to the docs for .slice():

Note that the lifetime of the resulting slice corresponds to the &self borrow. If you want a slice with the same lifetime as an existing view, clone/copy the view if necessary and then use .slice_move() or .slice_collapse().

and add the following to the docs for .slice_mut():

Note that the lifetime of the resulting slice corresponds to the &mut self borrow. If you want a slice with the same lifetime as an existing view, use .slice_move(), .multi_slice_move(), or .slice_collapse() on the view.

We could also add analogous comments to the docs of slice_axis/_mut (referencing slice_axis_inplace) and slice_each_axis/_mut (referencing slice_each_axis_inplace).

One other note: the markup of the links in this PR isn't quite right. A link should be formatted like this:

some text [the link text](url) more text

or like this:

some text [the link text] more text

[the link text]: url

Note also that as of Rust 1.48.0, it's possible to use the Rust path of an in-scope item as a "URL", and as of Rust 1.51.0, this works for associated items too, such as writing [.slice()](ArrayBase::slice).

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.

None yet

2 participants