Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for `as_slice` stabilization #27729
Comments
aturon
added
T-libs
B-unstable
labels
Aug 12, 2015
This comment has been minimized.
This comment has been minimized.
|
FWIW, "there is only one way to do it" has never been a hard design rule for |
This comment has been minimized.
This comment has been minimized.
|
There's also |
Ms2ger
referenced this issue
Aug 16, 2015
Open
Tracking: Unstable Rust feature gates used by Servo #5286
This comment has been minimized.
This comment has been minimized.
|
Nominating for 1.5 FCP discussion. |
aturon
added
the
I-nominated
label
Sep 23, 2015
This comment has been minimized.
This comment has been minimized.
|
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. |
alexcrichton
added
final-comment-period
and removed
I-nominated
labels
Sep 24, 2015
This comment has been minimized.
This comment has been minimized.
|
I'm generally I haven't heard of anyone who is actually using |
This comment has been minimized.
This comment has been minimized.
|
cc @carllerche |
This comment has been minimized.
This comment has been minimized.
|
I was using |
This comment has been minimized.
This comment has been minimized.
|
-1, unless you can present some damning case where all of the current three methods is insufficient. I'm already salty about having both |
This comment has been minimized.
This comment has been minimized.
|
@bstrie do you mean TOOWTDI? |
This comment has been minimized.
This comment has been minimized.
|
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 :)
|
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
Edit: actually, I don't see that |
This comment has been minimized.
This comment has been minimized.
|
I don’t see myself using |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Sep 25, 2015
|
As a recent learner of Rust, I've found the different ways of slicing to be confusing, and |
steveklabnik
referenced this issue
Sep 30, 2015
Merged
Call out slicing syntax more explicitly #28759
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this issue
Sep 30, 2015
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this issue
Sep 30, 2015
steveklabnik
added this to the 1.5 milestone
Oct 1, 2015
This comment has been minimized.
This comment has been minimized.
|
I'm sympathetic to limiting the proliferation of conversion functions. |
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this during triage today and the decision was punt this to a future FCP. |
alexcrichton
removed
the
final-comment-period
label
Oct 22, 2015
This comment has been minimized.
This comment has been minimized.
|
This should be removed. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
I’ve ran +1 for deprecation. There are many replacements. (Which themselves are arguably redundant with each other already.) |
This comment has been minimized.
This comment has been minimized.
I don’t think this is comparable. |
This comment has been minimized.
This comment has been minimized.
|
another random opinion... I like the explicit conversion methods because it allows one to write Slicing syntax or the |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
|
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 |
bluss
closed this
Jan 5, 2016
bluss
reopened this
Jan 5, 2016
This comment has been minimized.
This comment has been minimized.
|
I wouldn't even really consider it redundant because there is no similar way already.
And if |
This comment has been minimized.
This comment has been minimized.
After this discussion, I am now slightly in favour of keeping
In the case of |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
I am too. I have many regrets about there being so many alternatives, but most of them are actually worse than |
This comment has been minimized.
This comment has been minimized.
|
I am also relatively swayed by this discussion in favor of keeping |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Jan 14, 2016
It has the same benefits that justify Every email that this thread generates costs more time than adding |
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this in triage recently, and the decision was to stabilize |
aturon commentedAug 12, 2015
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_slicemethod follows the usual conversion conventions, but has been somewhat controversial due to offering "yet another way" to perform the conversion (in addition toas_refand&*).