You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is there a reason why the first two methods below are taking a write lock on the context, even though they don't expose a mutable InputState reference to the reader function? The inconsistency with the rest of the code of that implementation caught my eye, and got me curious as for the reasons why.
impl Context {
#[inline]
pub fn input<R>(&self, reader: impl FnOnce(&InputState) -> R) -> R {
self.write(move |ctx| reader(&ctx.viewport().input))
}
/// This will create a `InputState::default()` if there is no input state for that viewport
#[inline]
pub fn input_for<R>(&self, id: ViewportId, reader: impl FnOnce(&InputState) -> R) -> R {
self.write(move |ctx| reader(&ctx.viewport_for(id).input))
}
/// Read-write access to [`InputState`].
#[inline]
pub fn input_mut<R>(&self, writer: impl FnOnce(&mut InputState) -> R) -> R {
self.input_mut_for(self.viewport_id(), writer)
}
/// This will create a `InputState::default()` if there is no input state for that viewport
#[inline]
pub fn input_mut_for<R>(&self, id: ViewportId, writer: impl FnOnce(&mut InputState) -> R) -> R {
self.write(move |ctx| writer(&mut ctx.viewport_for(id).input))
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey folks,
is there a reason why the first two methods below are taking a
write
lock on the context, even though they don't expose a mutableInputState
reference to the reader function? The inconsistency with the rest of the code of that implementation caught my eye, and got me curious as for the reasons why.Beta Was this translation helpful? Give feedback.
All reactions