Skip to content

An alternate design for StreamingIterator based on HRTBs #25

Closed
@Kestrer

Description

@Kestrer

The design is this:

pub trait StreamingIterator<'s, ImplicitBound: sealed::Sealed = sealed::ImplicitBounds<'s, Self>> {
    type Item;
    fn next(&'s mut self) -> Option<Self::Item>;
}

mod sealed {
    pub trait Sealed {}
    pub struct ImplicitBounds<'a, T: ?Sized>(&'a T); // T: 'a
    impl<T: ?Sized> Sealed for ImplicitBounds<'_, T> {}
}

Here is a playground of it being used to implement WindowsMut. Note that it is working when neither the iterator nor the iterator's item are 'static.

Note that I have only a vague idea of how this actually works, I'm not an expert on rustc. But the general idea is that the hidden type parameter on the trait effectively gives a where Self: 's bound to the trait, but in a special way that works with HRTBs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions