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 [..] and as_slice documentation #28359

Closed
rseymour opened this issue Sep 11, 2015 · 6 comments
Closed

Improve [..] and as_slice documentation #28359

rseymour opened this issue Sep 11, 2015 · 6 comments

Comments

@rseymour
Copy link

The section of the Rust book on Slices is nice (hard to find in primitive types) but it gives more information on [..](and it's origins in [1..] and [3..5] [..3] type indexing):

https://github.com/rust-lang/rust/blob/master/src/doc/trpl/primitive-types.md#slices

The actual docs for slice just intro it out of nowhere with no explanation of the fact that it's syntactic sugar for as_slice.

//! let int_slice = &vec[..];

This is a subtle thing, but since googling for [..] is hard and github searching for "[..]" is basically impossible, it's a tough thing to have to search out, let alone explain on the web.

Thanks! Anyway, great documentation, hard to search for without single page, but I would want to fix the docs in libcollections if possible since ideally it would have more information and detail there.

-Rich

@steveklabnik
Copy link
Member

hard to search for without single page

cc #22786

I completely agree that this is a bit weird right now. I'd like to add something, but I'm not sure what form it should take.

@alexispurslane
Copy link
Contributor

It doesn't seem like as_slice is defined in rust nightly. Playground link: https://play.rust-lang.org/?gist=b220989e7c850403dd7b&version=stable

@steveklabnik
Copy link
Member

In general, as_slice() is behind the convert feature gate, and &foo[..] should be used instead.

http://is.gd/srNESj

@alexispurslane
Copy link
Contributor

Ah. That explains it. So it seems like as_slice and [..] are actually different things, because one is behind a feature gate, and one is not. Am I right about this?

@steveklabnik
Copy link
Member

They do the same thing. The syntax was added later, one of the motivations was that .as_slice() is common and quite long, as well as an inexpensive operation.

@leoyvens
Copy link
Contributor

👍 to this, it's totally ungoogleable, from the reference I concluded it's an use of the range operator, the book section could mention it.

steveklabnik added a commit to steveklabnik/rust that referenced this issue Sep 30, 2015
steveklabnik added a commit to steveklabnik/rust that referenced this issue Sep 30, 2015
Fixes rust-lang#28359

I'm not doing more here because it's unclear that `as_slice()` is even going to stick around, see rust-lang#27729
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

No branches or pull requests

4 participants