RFC 1152: slice-string-symmetry

libs (slice)

Summary

Add some methods that already exist on slices to strings. Specifically, the following methods should be added:

Motivation

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

Specifically, it is currently very difficult to construct a Box<str>, while it is fairly simple to make a Box<[T]> by using Vec::into_boxed_slice. This RFC proposes a means of creating a Box<str> by converting a String.

Detailed design

Add the following method to str, presumably as an inherent method:

Add the following method to String as an inherent method:

Drawbacks

None, yet.

Alternatives

Unresolved questions

None.