Skip to content
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 OneSidedRange #69780

Closed
cramertj opened this issue Mar 6, 2020 · 3 comments
Closed

Tracking Issue for OneSidedRange #69780

cramertj opened this issue Mar 6, 2020 · 3 comments
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@cramertj
Copy link
Member

cramertj commented Mar 6, 2020

The feature gate for the issue is #![feature(one_sided_range)], introduced in #62282.

@cramertj cramertj added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC labels Mar 6, 2020
@JohnTitor JohnTitor added the B-unstable Blocker: Implemented in the nightly compiler and unstable. label Mar 6, 2020
@KodrAus
Copy link
Contributor

KodrAus commented Jul 29, 2020

Since the linked implementation PR was closed (just from inactivity) we don't really have a feature to track here yet. I'll go ahead and close this one now, but if #62282 resurfaces in the future we can re-open this!

@its-the-shrimp
Copy link
Contributor

Should this be reopened now that OneSidedRange is on nightly? No clue when it got there, but it is most definitely there, my eyes don't deceive me

https://doc.rust-lang.org/std/ops/trait.OneSidedRange.html

@its-the-shrimp
Copy link
Contributor

its-the-shrimp commented Jun 18, 2024

Also, should this trait be unsafe? Since the guarantee of

must return Bound::Unbounded from one of RangeBounds::start_bound or RangeBounds::end_bound.

Can't be represented by this trait directly (in its current form at least)

Making it unsafe will allow for the following use of it:

fn f<T>(x: impl OneSidedRange<T>) {
    match (x.start_bound(), x.end_bound()) {
        (start, Bound::Unbounded) => todo!(),
        (Bound::Unbounded, end) => todo!(),
        _ => unsafe { // Safety: guaranteed by `OneSidedRange`
            std::hint::unreachable_unchecked()
        }
    }
}

Another possibility is the following API for this trait:

enum OnlyBound<T> {
    Start(Bound<T>),
    End(Bound<T>),
}

trait OneSidedRange<T>: RangeBounds<T> {
    fn bound(&self) -> OnlyBound<T> {
        match (self.start_bound(), self.end_bound()) {
            (start, Bound::Unbounded) => OnlyBound::Start(start),
            (Bound::Unbounded, end) => OnlyBound::End(end),
            _ => unreachable!(),
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants