-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Consider adding non-draining event reader iterator #4083
Comments
One thing with this method actually is that we might be able to use a |
That would be strange, if I scope my peek, then I cannot peek again after that because the |
What if we implemented |
Indeed, I have just started a slight rework of |
That makes sense. I guess I was thinking more for simple systems. But yeah, this wouldn't work if you created the peek in an inner function call, for example.
That might be possible too, since the reader should only drop at the end of the main system. Although, that might be bad too if you need to take advantage of the 1-frame delay... |
Would that require |
I don't think so: we could clone the internal state, and the references to the events. The events themselves are never moved into the EventReader at all: they stay put in |
@alice-i-cecile can you explain that statement please? |
The underlying event information can be accessed through The other workaround that comes to mind is a bit sillier, but quite a lot simpler: simply add two |
Doesn't it rely on |
Each local is a different value. Consider: fn sys(a: Local<u32>, b: Local<u32>){
let a: &mut u32 = &mut *a;
let b: &mut u32 = &mut *b;
} Which compiles and runs fine. |
Looks like this was resolved by #12777. |
What problem does this solve or what need does it fill?
Trying to loop over received events of an
EventReader<E>
twice or more in the same system on the same frame. Currentlyiter()
drains, so all but the first iteration time return 0 event.This is also confusing since
iter()
on say,Vev<T>
, will not drain, and sinceEventReader::iter()
is the only method available it's easy to not think and misuse it.What solution would you like?
Add a non-draining iterator with an explicit name, making it obvious this should not be your default choice for new users.
Something like:
or
This not only solves the non-draining issue, but also shows in docs that there are 2 types of iterators, which prompt the user to question which one they need, avoiding the confusion with the non-draining
iter()
found in the standard library.What alternative(s) have you considered?
Manual event clearing. This is overkill and error-prone, much more so than calling (N-1) times the non-draining iterator proposed and one last time the draining one. Or doing N non-draining and a manual clear().
Additional context
I understand the default
iter()
being draining to avoid user error, so avoiding on purpose any method name already existing on standard Rust iterators likedrain()
to avoid confusion.iter_peek()
sounds good and longer (so less enticing) thaniter()
but we can even make it even less likely to be used likeiter_without_draining_advanced_use_only()
, as long as we provide an escape hatch out of the always-drain default we have now.The text was updated successfully, but these errors were encountered: