-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking issue for as_slice
stabilization
#27729
Comments
FWIW, "there is only one way to do it" has never been a hard design rule for |
There's also |
Nominating for 1.5 FCP discussion. |
This issue is now entering its cycle-long FCP for conclusion at 1.5. The libs team was a little up in the air about whether to deprecate or stabilize these methods. On one hand some are already stable (e.g. |
I'm generally 👎 on this, personally, for the "yet another way to do it" angle. I haven't heard of anyone who is actually using |
cc @carllerche |
I was using |
-1, unless you can present some damning case where all of the current three methods is insufficient. I'm already salty about having both |
@bstrie do you mean TOOWTDI? |
TIMTOWTDI is Perl's "There is more than one way to do it", whereas TOOWTDI
is "there is only one way to do it" from Python, so yes, I'm guessing he
meant the latter :)
|
Multiple ways of doing the same thing enable inconsistencies and disagreement about superficial issues. I think we should avoid multiple ways of doing the same things when possible. That said, a method is better for discoverability than syntactic sugar. Deprecating |
👎 It's superfluous to Edit: actually, I don't see that |
I don’t see myself using |
As a recent learner of Rust, I've found the different ways of slicing to be confusing, and |
Fixes rust-lang#28359 I'm not doing more here because it's unclear that `as_slice()` is even going to stick around, see rust-lang#27729
I'm sympathetic to limiting the proliferation of conversion functions. |
The libs team discussed this during triage today and the decision was punt this to a future FCP. |
This should be removed. |
Nominating for discussion. This unstable method makes more harm than good by misleading people into thinking String -> &str itself is unstable in all forms(!) (As seen in user questions). It should be removed or stabilized ASAP. Edit: I'm primarily talking about .as_str(), which shares this tracking issue. as_slice may have the same concerns. |
I’ve ran +1 for deprecation. There are many replacements. (Which themselves are arguably redundant with each other already.) |
I don’t think this is comparable. |
another random opinion... I like the explicit conversion methods because it allows one to write Slicing syntax or the |
I'm with @alexcrichton here. What is the downside of keeping the conversion method in place, given that it follows all of the standard conventions? The answer can't be "there should only be a single way to do it" because (1) there are already many other ways to do it and (2) in general, that's not been tops on the list of concerns with the standard library; we violate that principle all over the place, and for good reason. My standard argument here is that there is little effective burden in providing the method, because it follows an expected convention -- if you see its name, you know immediately what it's doing. Moreover, offering such a conventional method has ergonomic benefits, not just for the scenarios @alexcrichton described, but because ad hoc Put differently, I think "all expected conventional methods/impls are present" significantly outweighs "there's more than one way to do it" in terms of ergonomic/understandability concerns. |
It's an unstable feature, with plenty of alternatives. In that light, we're not keeping them in place, as much as adding the methods to the language. The "not used very much" arguments are weak for the same reason: you're never supposed to use these, there are stable equivalents. But would you use them, and is this addition a net benefit to Rust? On balance, I think these methods (Vec::as_slice and String::as_str) are ok, but I'm very much against there being more than one obvious way to do it in general. In particular do not want us to continue adding conversion methods as a standard solution. These methods are consistent with
These methods are also strictly better than generic conversion methods These methods possibly heighten confusion. |
I would love for someone to lay out the concrete benefits of following this dictum, rather than just asserting the principle. As I mentioned in my comment, we've never given this principle much credence in the standard library; we've valued things like consistent API surfaces more highly. And I've tried to argue why it matters: that once you know the convention around conversion methods, you can find and understand them very easily -- an ergonomic win with no maintenance downside.
What is the confusion you anticipate about? I believe our conversion method conventions are pretty clear.
As you argued at the beginning of your comment, it's hard to really say that until everything under discussion is stable :) For myself, I'd definitely use |
To make sure that we don't end up adding lots of redundant ways to do everything. Isn't The example when expanded to
Yes, but I think that you will not use |
I wouldn't even really consider it redundant because there is no similar way already.
And if |
After this discussion, I am now slightly in favour of keeping
In the case of |
Good points. The language enforcing a style certainly helps with the ambiguity, and having the choice (and settling on a style) is a bit of a burden. While I obviously feel that it's important to have One situation where it comes up somewhat often for me is |
I am too. I have many regrets about there being so many alternatives, but most of them are actually worse than |
I am also relatively swayed by this discussion in favor of keeping |
It has the same benefits that justify Every email that this thread generates costs more time than adding |
The libs team discussed this in triage recently, and the decision was to stabilize |
This commit stabilizes and deprecates the FCP (final comment period) APIs for the upcoming 1.7 beta release. The specific APIs which changed were: Stabilized * `Path::strip_prefix` (renamed from `relative_from`) * `path::StripPrefixError` (new error type returned from `strip_prefix`) * `Ipv4Addr::is_loopback` * `Ipv4Addr::is_private` * `Ipv4Addr::is_link_local` * `Ipv4Addr::is_multicast` * `Ipv4Addr::is_broadcast` * `Ipv4Addr::is_documentation` * `Ipv6Addr::is_unspecified` * `Ipv6Addr::is_loopback` * `Ipv6Addr::is_unique_local` * `Ipv6Addr::is_multicast` * `Vec::as_slice` * `Vec::as_mut_slice` * `String::as_str` * `String::as_mut_str` * `<[T]>::clone_from_slice` - the `usize` return value is removed * `<[T]>::sort_by_key` * `i32::checked_rem` (and other signed types) * `i32::checked_neg` (and other signed types) * `i32::checked_shl` (and other signed types) * `i32::checked_shr` (and other signed types) * `i32::saturating_mul` (and other signed types) * `i32::overflowing_add` (and other signed types) * `i32::overflowing_sub` (and other signed types) * `i32::overflowing_mul` (and other signed types) * `i32::overflowing_div` (and other signed types) * `i32::overflowing_rem` (and other signed types) * `i32::overflowing_neg` (and other signed types) * `i32::overflowing_shl` (and other signed types) * `i32::overflowing_shr` (and other signed types) * `u32::checked_rem` (and other unsigned types) * `u32::checked_neg` (and other unsigned types) * `u32::checked_shl` (and other unsigned types) * `u32::saturating_mul` (and other unsigned types) * `u32::overflowing_add` (and other unsigned types) * `u32::overflowing_sub` (and other unsigned types) * `u32::overflowing_mul` (and other unsigned types) * `u32::overflowing_div` (and other unsigned types) * `u32::overflowing_rem` (and other unsigned types) * `u32::overflowing_neg` (and other unsigned types) * `u32::overflowing_shl` (and other unsigned types) * `u32::overflowing_shr` (and other unsigned types) * `ffi::IntoStringError` * `CString::into_string` * `CString::into_bytes` * `CString::into_bytes_with_nul` * `From<CString> for Vec<u8>` * `From<CString> for Vec<u8>` * `IntoStringError::into_cstring` * `IntoStringError::utf8_error` * `Error for IntoStringError` Deprecated * `Path::relative_from` - renamed to `strip_prefix` * `Path::prefix` - use `components().next()` instead * `os::unix::fs` constants - moved to the `libc` crate * `fmt::{radix, Radix, RadixFmt}` - not used enough to stabilize * `IntoCow` - conflicts with `Into` and may come back later * `i32::{BITS, BYTES}` (and other integers) - not pulling their weight * `DebugTuple::formatter` - will be removed * `sync::Semaphore` - not used enough and confused with system semaphores Closes rust-lang#23284 cc rust-lang#27709 (still lots more methods though) Closes rust-lang#27712 Closes rust-lang#27722 Closes rust-lang#27728 Closes rust-lang#27735 Closes rust-lang#27729 Closes rust-lang#27755 Closes rust-lang#27782 Closes rust-lang#27798
This commit stabilizes and deprecates the FCP (final comment period) APIs for the upcoming 1.7 beta release. The specific APIs which changed were: Stabilized * `Path::strip_prefix` (renamed from `relative_from`) * `path::StripPrefixError` (new error type returned from `strip_prefix`) * `Ipv4Addr::is_loopback` * `Ipv4Addr::is_private` * `Ipv4Addr::is_link_local` * `Ipv4Addr::is_multicast` * `Ipv4Addr::is_broadcast` * `Ipv4Addr::is_documentation` * `Ipv6Addr::is_unspecified` * `Ipv6Addr::is_loopback` * `Ipv6Addr::is_unique_local` * `Ipv6Addr::is_multicast` * `Vec::as_slice` * `Vec::as_mut_slice` * `String::as_str` * `String::as_mut_str` * `<[T]>::clone_from_slice` - the `usize` return value is removed * `<[T]>::sort_by_key` * `i32::checked_rem` (and other signed types) * `i32::checked_neg` (and other signed types) * `i32::checked_shl` (and other signed types) * `i32::checked_shr` (and other signed types) * `i32::saturating_mul` (and other signed types) * `i32::overflowing_add` (and other signed types) * `i32::overflowing_sub` (and other signed types) * `i32::overflowing_mul` (and other signed types) * `i32::overflowing_div` (and other signed types) * `i32::overflowing_rem` (and other signed types) * `i32::overflowing_neg` (and other signed types) * `i32::overflowing_shl` (and other signed types) * `i32::overflowing_shr` (and other signed types) * `u32::checked_rem` (and other unsigned types) * `u32::checked_shl` (and other unsigned types) * `u32::saturating_mul` (and other unsigned types) * `u32::overflowing_add` (and other unsigned types) * `u32::overflowing_sub` (and other unsigned types) * `u32::overflowing_mul` (and other unsigned types) * `u32::overflowing_div` (and other unsigned types) * `u32::overflowing_rem` (and other unsigned types) * `u32::overflowing_neg` (and other unsigned types) * `u32::overflowing_shl` (and other unsigned types) * `u32::overflowing_shr` (and other unsigned types) * `ffi::IntoStringError` * `CString::into_string` * `CString::into_bytes` * `CString::into_bytes_with_nul` * `From<CString> for Vec<u8>` * `From<CString> for Vec<u8>` * `IntoStringError::into_cstring` * `IntoStringError::utf8_error` * `Error for IntoStringError` Deprecated * `Path::relative_from` - renamed to `strip_prefix` * `Path::prefix` - use `components().next()` instead * `os::unix::fs` constants - moved to the `libc` crate * `fmt::{radix, Radix, RadixFmt}` - not used enough to stabilize * `IntoCow` - conflicts with `Into` and may come back later * `i32::{BITS, BYTES}` (and other integers) - not pulling their weight * `DebugTuple::formatter` - will be removed * `sync::Semaphore` - not used enough and confused with system semaphores Closes rust-lang#23284 cc rust-lang#27709 (still lots more methods though) Closes rust-lang#27712 Closes rust-lang#27722 Closes rust-lang#27728 Closes rust-lang#27735 Closes rust-lang#27729 Closes rust-lang#27755 Closes rust-lang#27782 Closes rust-lang#27798
Over time, the way that you convert e.g. a vector to a slice has transformed repeatedly. With deref coercions, it's usually implicit, but there are still some cases where you need to do it explicitly.
The
as_slice
method follows the usual conversion conventions, but has been somewhat controversial due to offering "yet another way" to perform the conversion (in addition toas_ref
and&*
).The text was updated successfully, but these errors were encountered: