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

add set difference, intersection, union, fix sum error op #199

Merged
merged 4 commits into from
Dec 6, 2020

Conversation

tgolsson
Copy link
Contributor

@tgolsson tgolsson commented Dec 6, 2020

This adds HashSet::{difference, intersection, union} methods. To make that doable it adds more blanket implementations for TypeOf so we can take self as Ref<Self> in receiver position. This required removing one static type declaration. This required removing one static type declaration for `Ref - I can't really tell the extent of the impact that has, but that specific incantation seems to only be used in one FromValue declaration.

Also fixes a minor copy-paste error in Iterator summation leading to very confusing error messages.

@tgolsson tgolsson requested a review from udoprog December 6, 2020 16:43
@udoprog udoprog added the enhancement New feature or request label Dec 6, 2020
fn next(&mut self) -> Option<Self::Item> {
loop {
// guaranteed to leave here unless the iterator is unbounded
let elt = self.this.next()?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe clear self.other once iteration is completed to release the reference?

@udoprog
Copy link
Collaborator

udoprog commented Dec 6, 2020

Looks good! Minor nonblocking nit.

@tgolsson
Copy link
Contributor Author

tgolsson commented Dec 6, 2020

@udoprog this should do if I understood you correctly.

@udoprog
Copy link
Collaborator

udoprog commented Dec 6, 2020

Yeah, exactly! I think the loop can be cleaned up a bit:

let other = self.other.take()?;

loop {
    let item = self.this.next()?;

    if other.set.contains(&item) {
        self.other = Some(other);
        return Some(item);
    }
}

I.e. if other is not set, the iterator has completed. If this completes, then other is not restored.

@tgolsson tgolsson merged commit c55fe69 into rune-rs:main Dec 6, 2020
@udoprog udoprog added the changelog Issue has been added to the changelog label Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog Issue has been added to the changelog enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants