-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 new_range_api
(part of RFC 3550)
#125687
Comments
Capturing something from a verbal discussion: In theory, since the new range types aren't iterators directly, and just get turned into iterators, we could automatically handle |
We discussed this in today's @rust-lang/libs-api meeting, and our conclusion was: the usefulness of |
We discussed the unresolved questions in the libs-api meeting yesterday.
There was a lot of opposition to inherent methods, especially However there was some support for adding an
We were mostly happy with how things are currently set out in the PR.
It should implement We also discussed the
This should be deferred for a future API proposal, only if it turns out there is a need for this.
Yes there should be. The case of converting an exhausted |
I understand the arguments for purity here, but the immense utility these offer should be taken into account. I'll remove them from the PR, but I think the question should be reconsidered before the edition change is stabilized. Arguments for `map` and `rev`I think range types are in a very unique position, here.
While shaving five characters and the shift necessary for the underscore is helpful, the remaining seven characters and two shifts for My position is that there is no other meaning we could assign to
|
Add `new_range_api` for RFC 3550 Initial implementation for rust-lang#125687 This includes a `From<legacy::RangeInclusive> for RangeInclusive` impl for convenience, instead of the `TryFrom` impl from the RFC. Having `From` is highly convenient and the debug assert should find almost all misuses. This includes re-exports of all existing `Range` types under `core::range`, plus the range-related traits (`RangeBounds`, `Step`, `OneSidedRange`) and the `Bound` enum. Currently the iterators are just wrappers around the old range types. Tracking issues: - rust-lang#123741 - rust-lang#125687
Rollup merge of rust-lang#125751 - pitaj:new_range_api, r=jhpratt Add `new_range_api` for RFC 3550 Initial implementation for rust-lang#125687 This includes a `From<legacy::RangeInclusive> for RangeInclusive` impl for convenience, instead of the `TryFrom` impl from the RFC. Having `From` is highly convenient and the debug assert should find almost all misuses. This includes re-exports of all existing `Range` types under `core::range`, plus the range-related traits (`RangeBounds`, `Step`, `OneSidedRange`) and the `Bound` enum. Currently the iterators are just wrappers around the old range types. Tracking issues: - rust-lang#123741 - rust-lang#125687
Hmm, so in release mode the iterator would have extra size that's not used? Seems like a shame, though I guess there's precedent with Fuse. |
I wish we had a Therefore I really like the idea of a Example use case:I have log store that tracks logs from a sensor net. It uses a timeseries database. The database stores logs based on their time in seconds, the log store api wants jiff::Timestamp. When fetching a range I need to convert between those. fn get(
&mut self,
range: RangeInclusive<jiff::Timestamp>,
) -> Result<ApiResult<Vec<ErrorEvent>>> {
let range = RangeInclusive::new(
range.start().as_second() as u64,
range.end().as_second() as u64,
);
//timeseries lookup using range. I use edit: added use case |
Thought: What's stopping anyone from making this an |
Feature gate:
#![feature(new_range_api)]
This is a tracking issue for the library additions that are part of RFC 3550: New range types
Tracking issue for the language change: #123741
This feature introduces new types implementing
Copy
andIntoIterator
that are meant to replace the legacy range types, which are!Copy
and implementIterator
directly.Public API
See the RFC for more details.
Steps / History
new_range_api
for RFC 3550 #125751Unresolved Questions
IterRangeFrom
overflow panic only after yielding the maximum value, without impacting release modeIterRangeInclusive
now that it is not bound by the API constraints of legacyRangeInclusive
?Iterator
present on the new range types (Decide which methods to add to newRange
types #125589)std::ops::range::
instead?IterRange
,IterRangeInclusive
or justIter
,IterInclusive
? OrRangeIter
,RangeInclusiveIter
, ...?RangeBounds
) also be moved under therange
module?RangeFrom
even implementIntoIterator
, or should it require an explicit.iter()
call? Using it as an iterator can be a footgun, usually people wantstart..=MAX
instead. Also, it is inconsistent withRangeTo
, which doesn't implementIntoIterator
either. But, it's extremely useful forit.zip(1..)
range.by_ref().next()
.RangeInclusive
?Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: