Skip to content

Commit 41ae6e6

Browse files
committed
Update with review feedback
1 parent cea65b3 commit 41ae6e6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

text/0000-slice-tail-redesign.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ fn shift_last_mut(&mut self) -> Option<(&mut T, &mut [T])>;
4040

4141
Existing code using `tail()` or `init()` could be translated as follows:
4242

43-
* `slice.tail()` becomes `slice.shift_first().unwrap().1` or `&slice[1..]`
44-
* `slice.init()` becomes `slice.shift_last().unwrap().1` or
45-
`&slice[..slice.len()-1]`
43+
* `slice.tail()` becomes `&slice[1..]`
44+
* `slice.init()` becomes `&slice[..slice.len()-1]` or
45+
`slice.shift_last().unwrap().1`
4646

4747
It is expected that a lot of code using `tail()` or `init()` is already either
4848
testing `len()` explicitly or using `first()` / `last()` and could be refactored
@@ -78,10 +78,12 @@ let (argv0, args_) = args.shift_first().unwrap();
7878

7979
# Drawbacks
8080

81-
The expression `slice.shift_last().unwrap.1` is more cumbersome than
81+
The expression `slice.shift_last().unwrap().1` is more cumbersome than
8282
`slice.init()`. However, this is primarily due to the need for `.unwrap()`
8383
rather than the need for `.1`, and would affect the more conservative solution
84-
(of making the return type `Option<&[T]>`) as well.
84+
(of making the return type `Option<&[T]>`) as well. Furthermore, the more
85+
idiomatic translation is `&slice[..slice.len()-1]`, which can be used any time
86+
the slice is already stored in a local variable.
8587

8688
# Alternatives
8789

@@ -90,6 +92,10 @@ more conservative change mentioned above. It still has the same drawback of
9092
requiring `.unwrap()` when translating existing code. And it's unclear what the
9193
function names should be (the current names are considered suboptimal).
9294

95+
Just deprecate the current methods without adding replacements. This gets rid of
96+
the odd methods today, but it doesn't do anything to make it easier to safely
97+
perform these operations.
98+
9399
# Unresolved questions
94100

95101
Is the name correct? There's precedent in this name in the form of

0 commit comments

Comments
 (0)