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

IntoEnumIterator::Iterator cannot be sent between threads safely #397

Open
ISibboI opened this issue Dec 25, 2024 · 1 comment
Open

IntoEnumIterator::Iterator cannot be sent between threads safely #397

ISibboI opened this issue Dec 25, 2024 · 1 comment

Comments

@ISibboI
Copy link

ISibboI commented Dec 25, 2024

Could IntoEnumIterator::Iterator implement Send, Sync and 'static? This would be very helpful when using it within frameworks that allow for async code or multithreading.

I guess the only restriction this poses is to some manual implementation of IntoEnumIterator that for some reasons are not thread-safe. But since enums are static objects, that should be pretty unlikely?

@Peternator7
Copy link
Owner

Hey @ISibboI, I've included a snippet below that might help solve your issue.

Regarding adding the trait bounds, it's a little bit tricky because EnumIter supports enums with generic types so long as they havea Default::default. With that restriction, it's possible to add a Send + Sync constraint using the change I just made in #402, but that wouldn't magically make every iterator 'static so you'd still need to do something like the snippet below, which makes me somewhat skeptical of adding additional bounds to the trait (especially since it isn't object safe in the first place).

#[derive(Debug, Eq, PartialEq, EnumIter)]
enum Color {
    Red,
    Blue,
    Yellow
}

#[test]
fn color_test_with_bounds() {
    color_iter_with_extra_bounds::<Color>();
}

fn color_iter_with_extra_bounds<E: IntoEnumIterator>() 
where
    <E as IntoEnumIterator>::Iterator: Send + Sync + 'static
{
    // stuff
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants