Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upRationale for "while let" design #132
Comments
bvssvni
added
draft
information
labels
Apr 19, 2016
bvssvni
removed
the
draft
label
Apr 19, 2016
bvssvni
closed this
May 28, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bvssvni commentedApr 19, 2016
•
edited
In the previous design, the emitted event was a
PistonWindowobject. This allowedfor e in window { ... }. There were some drawbacks with the old design:PistonWindowemitting events of its own type. They could not easily figure out how to use it and the idea behind the design was conceptually hard to grasp.Rc<RefCell<T>>was used, one had to do.borrow()and.borrow_mut()in many places. This was inconvenient and sometimes lead to runtime errors that were hard to debug.The new design uses "while let" instead of "for". This lets you borrow a mutable reference to the window only for the scope that pulls the event.
The event loop state is stored within the
PistonWindowobject, such that you can nest one event loop within another. This makes it easy to change scenes that has different event logic. For example, when going from a map to a level and back.