@@ -40,9 +40,9 @@ fn shift_last_mut(&mut self) -> Option<(&mut T, &mut [T])>;
40
40
41
41
Existing code using ` tail() ` or ` init() ` could be translated as follows:
42
42
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 `
46
46
47
47
It is expected that a lot of code using ` tail() ` or ` init() ` is already either
48
48
testing ` len() ` explicitly or using ` first() ` / ` last() ` and could be refactored
@@ -78,10 +78,12 @@ let (argv0, args_) = args.shift_first().unwrap();
78
78
79
79
# Drawbacks
80
80
81
- The expression ` slice.shift_last().unwrap.1 ` is more cumbersome than
81
+ The expression ` slice.shift_last().unwrap() .1 ` is more cumbersome than
82
82
` slice.init() ` . However, this is primarily due to the need for ` .unwrap() `
83
83
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.
85
87
86
88
# Alternatives
87
89
@@ -90,6 +92,10 @@ more conservative change mentioned above. It still has the same drawback of
90
92
requiring ` .unwrap() ` when translating existing code. And it's unclear what the
91
93
function names should be (the current names are considered suboptimal).
92
94
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
+
93
99
# Unresolved questions
94
100
95
101
Is the name correct? There's precedent in this name in the form of
0 commit comments