Skip to content

Tracking issue for step_trait stabilization #42168

Open
@scottmcm

Description

@scottmcm
Member

Split off from #27741 because the stabilization path for step_by has moved to being on iterators (#41439), and thus not using the Step trait.

(and probably more)

Activity

added
B-unstableBlocker: Implemented in the nightly compiler and unstable.
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on May 23, 2017
added a commit that references this issue on May 23, 2017

Rollup merge of rust-lang#42169 - scottmcm:new-step-trait-issue, r=al…

added 3 commits that reference this issue on May 24, 2017

Rollup merge of rust-lang#42169 - scottmcm:new-step-trait-issue, r=al…

Rollup merge of rust-lang#42169 - scottmcm:new-step-trait-issue, r=al…

added a commit that references this issue on May 26, 2017

Rollup merge of rust-lang#42169 - scottmcm:new-step-trait-issue, r=al…

added 2 commits that reference this issue on May 26, 2017

Rollup merge of rust-lang#42169 - scottmcm:new-step-trait-issue, r=al…

Rollup merge of rust-lang#42169 - scottmcm:new-step-trait-issue, r=al…

scottmcm

scottmcm commented on Jun 9, 2017

@scottmcm
MemberAuthor

Some progress on this in #42534

SimonSapin

SimonSapin commented on Jul 5, 2017

@SimonSapin
Contributor

PR #43077 does items 1 and 3 in the original message of this issue.

SimonSapin

SimonSapin commented on Jul 6, 2017

@SimonSapin
Contributor

I’ve removed the i128/u128 stuff from my PR because I suspect my mixed-signdeness mixed-width interger arithmetic was buggy. I also massaged the Step trait some more and came up with this:

/// Supporting trait for allowing ranges of various different types to be iterators.
#[unstable(feature = "step_trait",
           reason = "recently redesigned",
           issue = "42168")]
pub trait Step: Clone + PartialOrd + Sized {
    /// Returns the number of steps between two step objects. The count is
    /// inclusive of `start` and exclusive of `end`.
    ///
    /// Returns `None` if it is not possible to calculate `steps_between`
    /// without overflow.
    fn steps_between(start: &Self, end: &Self) -> Option<usize>;

    /// “Go forward” (for integers, add) the given number of steps, returning None on overflow.
    fn forward(&self, step_count: usize) -> Option<Self>;

    /// “Go backward” (for integers, subtract) the given number of steps, returning None on overflow.
    fn backward(&self, step_count: usize) -> Option<Self>;

    /// Modify the given inclusive range so that it becomes empty,
    /// for example by setting it to `1...0`.
    fn make_inclusive_range_empty(range: &mut ops::RangeInclusive<Self>);
}

How does it look?

I’m a bit uncertain of the exact impls for integers, there is up to 6 cases to consider: {smaller, same width, larger} than usize/isize × {signed, unsigned}.

89 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-iteratorsArea: IteratorsB-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-TrackedLibs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @alexcrichton@pnkfelix@SimonSapin@ExpHP@jonas-schievink

        Issue actions

          Tracking issue for `step_trait` stabilization · Issue #42168 · rust-lang/rust