Skip to content

Commit 566bb70

Browse files
committed
Remove str::{windows,chunks} and <[T]>::subslice_offset
1 parent e4372c4 commit 566bb70

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

text/0000-slice-string-symmetry.md

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,64 @@
55

66
# Summary
77

8-
Add some methods that already exist on slices to strings and vice versa.
9-
Specifically, the following methods should be added:
8+
Add some methods that already exist on slices to strings. Specifically, the
9+
following methods should be added:
1010

11-
- `str::chunks`
12-
- `str::windows`
1311
- `str::into_string`
14-
- `String::into_boxed_slice`
15-
- `<[T]>::subslice_offset`
12+
- `String::into_boxed_str`
1613

1714
# Motivation
1815

1916
Conceptually, strings and slices are similar types. Many methods are already
2017
shared between the two types due to their similarity. However, not all methods
2118
are shared between the types, even though many could be. This is a little
2219
unexpected and inconsistent. Because of that, this RFC proposes to remedy this
23-
by adding a few methods to both strings and slices to even out these two types’
24-
available methods.
20+
by adding a few methods to strings to even out these two types’ available
21+
methods.
2522

26-
# Detailed design
27-
28-
Add the following methods to `str`, presumably as inherent methods:
23+
Specifically, it is currently very difficult to construct a `Box<str>`, while it
24+
is fairly simple to make a `Box<[T]>` by using `Vec::into_boxed_slice`. This RFC
25+
proposes a means of creating a `Box<str>` by converting a `String`.
2926

30-
- `chunks(&self, n: usize) -> Chunks`: Returns an iterator that yields the
31-
*characters* (not bytes) of the string in groups of `n` at a time. Iterator
32-
element type: `&str`.
27+
# Detailed design
3328

34-
- `windows(&self, n: usize) -> Windows`: Returns an iterator over all contiguous
35-
windows of character length `n`. Iterator element type: `&str`.
29+
Add the following method to `str`, presumably as an inherent method:
3630

3731
- `into_string(self: Box<str>) -> String`: Returns `self` as a `String`. This is
3832
equivalent to `[T]`’s `into_vec`.
3933

40-
`split_at(&self, mid: usize) -> (&str, &str)` would also be on this list, but
41-
there is [an existing RFC](https://github.com/rust-lang/rfcs/pull/1123) for it.
42-
4334
Add the following method to `String` as an inherent method:
4435

45-
- `into_boxed_slice(self) -> Box<str>`: Returns `self` as a `Box<str>`,
36+
- `into_boxed_str(self) -> Box<str>`: Returns `self` as a `Box<str>`,
4637
reallocating to cut off any excess capacity if needed. This is required to
47-
provide a safe means of creating `Box<str>`.
48-
49-
Add the following method to `[T]` (for all `T`), presumably as an inherent
50-
method:
38+
provide a safe means of creating `Box<str>`. This is equivalent to `Vec<T>`’s
39+
`into_boxed_slice`.
5140

52-
- `subslice_offset(&self, inner: &[T]) -> usize`: Returns the offset (in
53-
elements) of an inner slice relative to an outer slice. Panics of `inner` is
54-
not contained within `self`.
5541

5642
# Drawbacks
5743

58-
- `str::subslice_offset` is already unstable, so creating a similar method on
59-
`[T]` is perhaps not such a good idea.
44+
None, yet.
6045

6146
# Alternatives
6247

63-
- Do a subset of the proposal. For example, the `Box<str>`-related methods could
64-
be removed.
48+
- The original version of this RFC had a few extra methods:
49+
- `str::chunks(&self, n: usize) -> Chunks`: Returns an iterator that yields
50+
the *characters* (not bytes) of the string in groups of `n` at a time.
51+
Iterator element type: `&str`.
52+
53+
- `str::windows(&self, n: usize) -> Windows`: Returns an iterator over all
54+
contiguous windows of character length `n`. Iterator element type: `&str`.
55+
56+
This and `str::chunks` aren’t really useful without proper treatment of
57+
graphemes, so they were removed from the RFC.
58+
59+
- `<[T]>::subslice_offset(&self, inner: &[T]) -> usize`: Returns the offset
60+
(in elements) of an inner slice relative to an outer slice. Panics of
61+
`inner` is not contained within `self`.
62+
63+
`str::subslice_offset` isn’t yet stable and its usefulness is dubious, so
64+
this method was removed from the RFC.
65+
6566

6667
# Unresolved questions
6768

0 commit comments

Comments
 (0)