In the "Slices" chapter, there are several sentences like this: "_It works the exact same way as string slices do, with a reference to the first element, and a length._". It's misleading because it induces that a slice's arguments are beginning and length, whereas they are beginning and end.
I might be misunderstanding you, but slices are definitely a pointer and a length, not a beginning and an end.
Aren't they written e.g s[1..3] for a 2 elements slice starting at the second element ?
Ah, I see the confusion here! So yes, you're right that that indexing syntax is beginning, end, but _the slice itself_ is a pointer and a length. Like:
let s = "slices";
let slice = &s[1..3];
Here, slice is a tuple: a pointer to l, and the number 2. That's the way it's implemented in memory.
I understand that, but it's an implementation detail. From the POV of the rust user a slice is just its indexing syntax. IMHO.
It's important to understand how it's represented though, and that slicing syntax is only one way to create a slice.
The answer is probably then to clarify the wording to better distinguish between the notation for ranges when creating a slice, and the in-memory representation of a slice.
Yes, agreed.
Precisely.
Most helpful comment
I understand that, but it's an implementation detail. From the POV of the rust user a slice is just its indexing syntax. IMHO.