Uh oh!
There was an error while loading. Please reload this page.
Second pass stabilization: slice and vec - #20061
Conversation
aturon
commented
Dec 20, 2014
Note @alexcrichton: I made the mistake of organizing the vec and slice files (they were previously totally haphazard). While that's a nice cleanup, it makes this somewhat rebase-hostile. I'd suggest high priority. Also, feel free to take over this PR and push it through if you like while I'm away. |
aturon
commented
Dec 20, 2014
@MrFloya @gankro: this is the PR I was mentioning |
Gankra
commented
Dec 21, 2014
I wonder if we should perhaps hold off on properly deprecating from_fn, from_elem, grow_fn and grow while we figure out the trusted_len story. It's an unfortunate perf regression to cause in the interim. |
reem
commented
Dec 21, 2014
Was |
Gankra
commented
Dec 21, 2014
It was not part of any collections RFC, to my knowledge. Likely dark work-week cabals. |
aturon
commented
Dec 27, 2014
I'm open to that -- we could leave them as
No, this was a bit of bikeshedding that came up during the first round of |
There was a problem hiding this comment.
I may have expected this to be get_mut_unchecked, although I may not quite have the ordering of suffixes right in my head.
There was a problem hiding this comment.
alexcrichton
commented
Dec 29, 2014
Sorry for being a little slow getting to this @aturon! I've looked things over and I'm quite happy with this! Just a few nits here and there and I think it's good to go. |
e124b54 to
3ca66a8Compareaturon
commented
Dec 30, 2014
I've added almost all your suggestions, except for the change to binary search's return type (which didn't seem worthwhile to me). |
8a18146 to
b82a53bComparereem
commented
Dec 30, 2014
@aturon I prefer |
aturon
commented
Dec 30, 2014
OK, that's a pretty compelling argument, since the use of I will adjust accordingly, thanks! |
b82a53b to
bd5f7a5CompareThis commit takes a second pass through the `vec` module to stabilize its API. The changes are as follows: **Stable**: * `dedup` * `from_raw_parts` * `insert` * `into_iter` * `is_empty` * `remove` * `reserve_exact` * `reserve` * `retain` * `swap_remove` * `truncate` **Deprecated**: * `from_fn`, `from_elem`, `grow_fn` and `grow`, all deprecated in favor of iterators. See rust-lang/rfcs#509 * `partition`, `partitioned`, deprecated in favor of a new, more general iterator consumer called `partition`. * `unzip`, deprecated in favor of a new, more general iterator consumer called `unzip`. A few remaining methods are left at experimental status. [breaking-change]
This commit takes a second pass through the `slice` module to stabilize its API. The changes are as follows: **Stable**: * `as_mut_slice` * `as_ptr`, `as_mut_ptr` * `binary_search_by` (was: `binary_search`) * `binary_search` (was: `binary_search_elem`) * `chunks`, `chunks_mut` * `contains` * `ends_with` * `first`, `first_mut` (was: `head`) * `get_unchecked`, `get_unchecked_mut` (was: `unsafe_get`) * `get` * `is_empty` * `iter`, `iter_mut` * `len` * `reverse` * `sort_by` * `sort` * `split_at`, `split_at_mut` * `split_mut`, `splitn_mut`, `rsplitn_mut` * `split`, `splitn`, `rsplitn` * `starts_with` * `swap` * `to_vec` * `windows` **Deprecated**: * `head`, `head_mut` (renamed as above) * `unsafe_get`, `unsafe_mut` (renamed as above) * `binary_search_elem` (renamed as above) * `partitioned`, deprecated in favor of a new, more general iterator consumer called `partition`. * `BinarySearchResult`, deprecated in favor of `Result<uint, uint>` [breaking-change]
We've long had traits `StrVector` and `VectorVector` providing `concat`/`connect` and `concat_vec`/`connect_vec` respectively. The reason for the distinction is that coherence rules did not used to be robust enough to allow impls on e.g. `Vec<String>` versus `Vec<&[T]>`. This commit consolidates the traits into a single `SliceConcatExt` trait provided by `slice` and the preldue (where it replaces `StrVector`, which is removed.) [breaking-change]
1708a66 to
bd69b74Comparea004ff5 to
cb2eca3Compare215f2fa to
6abfac0CompareConflicts: src/libcollections/slice.rs src/libcollections/vec.rs src/libstd/sys/windows/os.rs
c443ef3 to
29377eaComparealexcrichton
commented
Dec 31, 2014
Landed in #20360 |
bluss
commented
Jan 1, 2015
Why did you change .remove() and .swap_remove to not return Option? It seems to contradict the RFC. |
bluss
commented
Jan 1, 2015
Also, why do we mark methods stable even if they were just changed? |
tomaka
commented
Jan 1, 2015
Gankra
commented
Jan 1, 2015
Yes, this change flew under my radar, I would be interested in the detailed rationale, as this is technically a functionality regression (even though it improves ergonomics in the expected case). |
aturon
commented
Jan 1, 2015
@bluss Thanks for bringing this to my attention! The RFC mistakenly had
This was part of rolling out error conventions for The reason for marking it stable here was that I believed this was bringing into line with the old conventions RFC. However, as I said above, that RFC had a mistake. I'm going to file an amendment to clarify the intended conventions and their rationale. If discussion there determines it should be otherwise, there's still time to change before 1.0-beta. |
SimonSapin
commented
Jan 2, 2015
@aturon, Where was this discussed? What is the rationale? It seems opposite with the earlier trend of avoiding panic when possible, e.g. #11129. And taking an index seems a fairly arbitrary criteria for different error handling. If you want to panic on failure it’s very easy to add |
aturon
commented
Jan 2, 2015
@SimonSapin Some of the early discussion was here, although the repo seems to be missing the follow-up discussion after doing the experiment. This was also part of the (many, many) discussions about error conventions, though I don't recall how much was on IRC vs other forums. In any case, two things: Why I believe this is the right guidelineI stand by the guideilne. It has a very simple rationale: almost all of the time, if you have managed to produce an index, either it's "special" (in practice, 0), or it was computed in a way that guarantees it's in bounds. For special indexes (0 and len() - 1) we tend to provide convenience methods (like FWIW, I tried many variations on the error conventions for While we have moved away from panicicking in general, we are not doing so blindly. The accepted conventions leave it to the API designer to choose what to treat as contracts (resulting in panics) and when to return results. It depends a lot on how a given API is used in practice and what knowledge clients typically have. The above guideline for To my mind, the pushback against changing But I could be wrong!As I mentioned above, I will be posting an amendment to the RFC to make sure these considerations are recorded highly visibly and to give people a chance to weigh in. If there is strong disagreement, there is still time to change the API before 1.0-final. |
SimonSapin
commented
Jan 2, 2015
That makes sense. Thanks for the explanation.
Yes please. |
fix: In "Wrap return type" assist, don't wrap exit points if they already have the right type
fix: In "Wrap return type" assist, don't wrap exit points if they already have the right type
Second pass stabilization: vec
This PR takes a second pass through the
vecmodule tostabilize its API. The changes are as follows:
Stable:
dedupfrom_raw_partsinsertinto_iteris_emptyremovereserve_exactreserveretainswap_removetruncateDeprecated:
from_fn,from_elem,grow_fnandgrow, all deprecated infavor of iterators. See Collections Reform Part 2 rfcs#509
partition,partitioned, deprecated in favor of a new, moregeneral iterator consumer called
partition.unzip, deprecated in favor of a new, more general iteratorconsumer called
unzip.A few remaining methods are left at experimental status.
Second pass stabilization: slice
This PR takes a second pass through the
slicemodule tostabilize its API. The changes are as follows:
Stable:
as_mut_sliceas_ptr,as_mut_ptrbinary_search_by(was:binary_search)binary_search(was:binary_search_elem)chunks,chunks_mutcontainsends_withfirst,first_mut(was:head)get_unchecked,get_unchecked_mut(was:unsafe_get)getis_emptyiter,iter_mutlenpermutationsreversesort_bysortsplit_at,split_at_mutsplit_mut,splitn_mut,rsplitn_mutsplit,splitn,rsplitnstarts_withswapto_vecwindowsDeprecated:
head,head_mut(renamed as above)unsafe_get,unsafe_mut(renamed as above)binary_search_elem(renamed as above)partitioned, deprecated in favor of a new, moregeneral iterator consumer called
partition.BinarySearchResult, deprecated in favor ofResult<uint, uint>Unify concat and concat_vec
We've long had traits
StrVectorandVectorVectorprovidingconcat/connectandconcat_vec/connect_vecrespectively. Thereason for the distinction is that coherence rules did not used to be
robust enough to allow impls on e.g.
Vec<String>versusVec<&[T]>.This PR consolidates the traits into a single
SliceConcatExttraitprovided by
sliceand the prelude (where it replacesStrVector,which is removed.)
[breaking-change]
r? @alexcrichton