Replace app/app_mut on contexts with AsRef/AsMut impls

Co-Authored-By: Brooks Swinnerton <934497+bswinnerton@users.noreply.github.com>
This commit is contained in:
Nathan Sobo
2021-04-13 20:07:25 -06:00
co-authored by Brooks Swinnerton
parent 7469240a2e
commit 0a2d2aa684
10 changed files with 95 additions and 77 deletions
+24 -16
View File
@@ -1495,14 +1495,6 @@ impl<'a, T: Entity> ModelContext<'a, T> {
}
}
pub fn app(&self) -> &AppContext {
&self.app.ctx
}
pub fn app_mut(&mut self) -> &mut MutableAppContext {
self.app
}
pub fn background_executor(&self) -> &Arc<executor::Background> {
&self.app.ctx.background
}
@@ -1640,6 +1632,18 @@ impl<'a, T: Entity> ModelContext<'a, T> {
}
}
impl<M> AsRef<AppContext> for ModelContext<'_, M> {
fn as_ref(&self) -> &AppContext {
&self.app.ctx
}
}
impl<M> AsMut<MutableAppContext> for ModelContext<'_, M> {
fn as_mut(&mut self) -> &mut MutableAppContext {
self.app
}
}
impl<M> ReadModel for ModelContext<'_, M> {
fn read_model<T: Entity>(&self, handle: &ModelHandle<T>) -> &T {
self.app.read_model(handle)
@@ -1685,14 +1689,6 @@ impl<'a, T: View> ViewContext<'a, T> {
self.window_id
}
pub fn app(&self) -> &AppContext {
&self.app.ctx
}
pub fn app_mut(&mut self) -> &mut MutableAppContext {
self.app
}
pub fn background_executor(&self) -> &Arc<executor::Background> {
&self.app.ctx.background
}
@@ -1895,6 +1891,18 @@ impl<'a, T: View> ViewContext<'a, T> {
}
}
impl<M> AsRef<AppContext> for ViewContext<'_, M> {
fn as_ref(&self) -> &AppContext {
&self.app.ctx
}
}
impl<M> AsMut<MutableAppContext> for ViewContext<'_, M> {
fn as_mut(&mut self) -> &mut MutableAppContext {
self.app
}
}
impl<V> ReadModel for ViewContext<'_, V> {
fn read_model<T: Entity>(&self, handle: &ModelHandle<T>) -> &T {
self.app.read_model(handle)