Fix missed renames in #22632 (#23688)

Fix a bug where a GPUI macro still used `ModelContext`
Rename `AsyncAppContext` -> `AsyncApp`
Rename update_model, read_model, insert_model, and reserve_model to
update_entity, read_entity, insert_entity, and reserve_entity

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki
2025-01-26 23:37:34 +00:00
committed by GitHub
parent 83141d07e9
commit a6b1514246
118 changed files with 708 additions and 757 deletions
+9 -9
View File
@@ -1018,10 +1018,10 @@ impl App {
Ok(result)
})
}
/// Creates an `AsyncAppContext`, which can be cloned and has a static lifetime
/// Creates an `AsyncApp`, which can be cloned and has a static lifetime
/// so it can be held across `await` points.
pub fn to_async(&self) -> AsyncAppContext {
AsyncAppContext {
pub fn to_async(&self) -> AsyncApp {
AsyncApp {
app: self.this.clone(),
background_executor: self.background_executor.clone(),
foreground_executor: self.foreground_executor.clone(),
@@ -1039,8 +1039,8 @@ impl App {
}
/// Spawns the future returned by the given function on the thread pool. The closure will be invoked
/// with [AsyncAppContext], which allows the application state to be accessed across await points.
pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncAppContext) -> Fut) -> Task<R>
/// with [AsyncApp], which allows the application state to be accessed across await points.
pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncApp) -> Fut) -> Task<R>
where
Fut: Future<Output = R> + 'static,
R: 'static,
@@ -1598,11 +1598,11 @@ impl AppContext for App {
})
}
fn reserve_model<T: 'static>(&mut self) -> Self::Result<Reservation<T>> {
fn reserve_entity<T: 'static>(&mut self) -> Self::Result<Reservation<T>> {
Reservation(self.entities.reserve())
}
fn insert_model<T: 'static>(
fn insert_entity<T: 'static>(
&mut self,
reservation: Reservation<T>,
build_model: impl FnOnce(&mut Context<'_, T>) -> T,
@@ -1616,7 +1616,7 @@ impl AppContext for App {
/// Updates the entity referenced by the given model. The function is passed a mutable reference to the
/// entity along with a `ModelContext` for the entity.
fn update_model<T: 'static, R>(
fn update_entity<T: 'static, R>(
&mut self,
model: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
@@ -1632,7 +1632,7 @@ impl AppContext for App {
})
}
fn read_model<T, R>(
fn read_entity<T, R>(
&self,
handle: &Entity<T>,
read: impl FnOnce(&T, &App) -> R,
+25 -25
View File
@@ -14,13 +14,13 @@ use super::Context;
/// You're provided with an instance when calling [AppContext::spawn], and you can also create one with [AppContext::to_async].
/// Internally, this holds a weak reference to an `AppContext`, so its methods are fallible to protect against cases where the [AppContext] is dropped.
#[derive(Clone)]
pub struct AsyncAppContext {
pub struct AsyncApp {
pub(crate) app: Weak<AppCell>,
pub(crate) background_executor: BackgroundExecutor,
pub(crate) foreground_executor: ForegroundExecutor,
}
impl AppContext for AsyncAppContext {
impl AppContext for AsyncApp {
type Result<T> = Result<T>;
fn new<T: 'static>(
@@ -35,16 +35,16 @@ impl AppContext for AsyncAppContext {
Ok(app.new(build_model))
}
fn reserve_model<T: 'static>(&mut self) -> Result<Reservation<T>> {
fn reserve_entity<T: 'static>(&mut self) -> Result<Reservation<T>> {
let app = self
.app
.upgrade()
.ok_or_else(|| anyhow!("app was released"))?;
let mut app = app.borrow_mut();
Ok(app.reserve_model())
Ok(app.reserve_entity())
}
fn insert_model<T: 'static>(
fn insert_entity<T: 'static>(
&mut self,
reservation: Reservation<T>,
build_model: impl FnOnce(&mut Context<'_, T>) -> T,
@@ -54,10 +54,10 @@ impl AppContext for AsyncAppContext {
.upgrade()
.ok_or_else(|| anyhow!("app was released"))?;
let mut app = app.borrow_mut();
Ok(app.insert_model(reservation, build_model))
Ok(app.insert_entity(reservation, build_model))
}
fn update_model<T: 'static, R>(
fn update_entity<T: 'static, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
@@ -67,10 +67,10 @@ impl AppContext for AsyncAppContext {
.upgrade()
.ok_or_else(|| anyhow!("app was released"))?;
let mut app = app.borrow_mut();
Ok(app.update_model(handle, update))
Ok(app.update_entity(handle, update))
}
fn read_model<T, R>(
fn read_entity<T, R>(
&self,
handle: &Entity<T>,
callback: impl FnOnce(&T, &App) -> R,
@@ -80,7 +80,7 @@ impl AppContext for AsyncAppContext {
{
let app = self.app.upgrade().context("app was released")?;
let lock = app.borrow();
Ok(lock.read_model(handle, callback))
Ok(lock.read_entity(handle, callback))
}
fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
@@ -106,7 +106,7 @@ impl AppContext for AsyncAppContext {
}
}
impl AsyncAppContext {
impl AsyncApp {
/// Schedules all windows in the application to be redrawn.
pub fn refresh(&self) -> Result<()> {
let app = self
@@ -156,7 +156,7 @@ impl AsyncAppContext {
}
/// Schedule a future to be polled in the background.
pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncAppContext) -> Fut) -> Task<R>
pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncApp) -> Fut) -> Task<R>
where
Fut: Future<Output = R> + 'static,
R: 'static,
@@ -190,7 +190,7 @@ impl AsyncAppContext {
/// Reads the global state of the specified type, passing it to the given callback.
///
/// Similar to [`AsyncAppContext::read_global`], but returns an error instead of panicking
/// Similar to [`AsyncApp::read_global`], but returns an error instead of panicking
/// if no state of the specified type has been assigned.
///
/// Returns an error if no state of the specified type has been assigned the `AppContext` has been dropped.
@@ -221,12 +221,12 @@ impl AsyncAppContext {
pub struct AsyncWindowContext {
#[deref]
#[deref_mut]
app: AsyncAppContext,
app: AsyncApp,
window: AnyWindowHandle,
}
impl AsyncWindowContext {
pub(crate) fn new_context(app: AsyncAppContext, window: AnyWindowHandle) -> Self {
pub(crate) fn new_context(app: AsyncApp, window: AnyWindowHandle) -> Self {
Self { app, window }
}
@@ -317,29 +317,29 @@ impl AppContext for AsyncWindowContext {
self.window.update(self, |_, _, cx| cx.new(build_model))
}
fn reserve_model<T: 'static>(&mut self) -> Result<Reservation<T>> {
self.window.update(self, |_, _, cx| cx.reserve_model())
fn reserve_entity<T: 'static>(&mut self) -> Result<Reservation<T>> {
self.window.update(self, |_, _, cx| cx.reserve_entity())
}
fn insert_model<T: 'static>(
fn insert_entity<T: 'static>(
&mut self,
reservation: Reservation<T>,
build_model: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Self::Result<Entity<T>> {
self.window
.update(self, |_, _, cx| cx.insert_model(reservation, build_model))
.update(self, |_, _, cx| cx.insert_entity(reservation, build_model))
}
fn update_model<T: 'static, R>(
fn update_entity<T: 'static, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
) -> Result<R> {
self.window
.update(self, |_, _, cx| cx.update_model(handle, update))
.update(self, |_, _, cx| cx.update_entity(handle, update))
}
fn read_model<T, R>(
fn read_entity<T, R>(
&self,
handle: &Entity<T>,
read: impl FnOnce(&T, &App) -> R,
@@ -347,7 +347,7 @@ impl AppContext for AsyncWindowContext {
where
T: 'static,
{
self.app.read_model(handle, read)
self.app.read_entity(handle, read)
}
fn update_window<T, F>(&mut self, window: AnyWindowHandle, update: F) -> Result<T>
@@ -374,7 +374,7 @@ impl VisualContext for AsyncWindowContext {
self.window
}
fn new_window_model<T: 'static>(
fn new_window_entity<T: 'static>(
&mut self,
build_model: impl FnOnce(&mut Window, &mut Context<T>) -> T,
) -> Self::Result<Entity<T>> {
@@ -382,7 +382,7 @@ impl VisualContext for AsyncWindowContext {
.update(self, |_, window, cx| cx.new(|cx| build_model(window, cx)))
}
fn update_window_model<T: 'static, R>(
fn update_window_entity<T: 'static, R>(
&mut self,
view: &Entity<T>,
update: impl FnOnce(&mut T, &mut Window, &mut Context<T>) -> R,
+5 -5
View File
@@ -422,7 +422,7 @@ impl<T: 'static> Entity<T> {
cx: &C,
f: impl FnOnce(&T, &App) -> R,
) -> C::Result<R> {
cx.read_model(self, f)
cx.read_entity(self, f)
}
/// Updates the entity referenced by this model with the given function.
@@ -438,7 +438,7 @@ impl<T: 'static> Entity<T> {
where
C: AppContext,
{
cx.update_model(self, update)
cx.update_entity(self, update)
}
/// Updates the entity referenced by this model with the given function if
@@ -452,7 +452,7 @@ impl<T: 'static> Entity<T> {
where
C: VisualContext,
{
cx.update_window_model(self, update)
cx.update_window_entity(self, update)
}
}
@@ -650,7 +650,7 @@ impl<T: 'static> WeakEntity<T> {
crate::Flatten::flatten(
self.upgrade()
.ok_or_else(|| anyhow!("entity released"))
.map(|this| cx.update_model(&this, update)),
.map(|this| cx.update_entity(&this, update)),
)
}
@@ -685,7 +685,7 @@ impl<T: 'static> WeakEntity<T> {
crate::Flatten::flatten(
self.upgrade()
.ok_or_else(|| anyhow!("entity release"))
.map(|this| cx.read_model(&this, read)),
.map(|this| cx.read_entity(&this, read)),
)
}
}
+10 -10
View File
@@ -1,5 +1,5 @@
use crate::{
AnyView, AnyWindowHandle, App, AppContext, AsyncAppContext, DispatchPhase, Effect, EntityId,
AnyView, AnyWindowHandle, App, AppContext, AsyncApp, DispatchPhase, Effect, EntityId,
EventEmitter, FocusHandle, FocusOutEvent, Focusable, Global, KeystrokeObserver, Reservation,
SubscriberSet, Subscription, Task, WeakEntity, WeakFocusHandle, Window, WindowHandle,
};
@@ -183,7 +183,7 @@ impl<'a, T: 'static> Context<'a, T> {
/// Spawn the future returned by the given function.
/// The function is provided a weak handle to the model owned by this context and a context that can be held across await points.
/// The returned task must be held or detached.
pub fn spawn<Fut, R>(&self, f: impl FnOnce(WeakEntity<T>, AsyncAppContext) -> Fut) -> Task<R>
pub fn spawn<Fut, R>(&self, f: impl FnOnce(WeakEntity<T>, AsyncApp) -> Fut) -> Task<R>
where
T: 'static,
Fut: Future<Output = R> + 'static,
@@ -683,27 +683,27 @@ impl<'a, T> AppContext for Context<'a, T> {
self.app.new(build_model)
}
fn reserve_model<U: 'static>(&mut self) -> Reservation<U> {
self.app.reserve_model()
fn reserve_entity<U: 'static>(&mut self) -> Reservation<U> {
self.app.reserve_entity()
}
fn insert_model<U: 'static>(
fn insert_entity<U: 'static>(
&mut self,
reservation: Reservation<U>,
build_model: impl FnOnce(&mut Context<'_, U>) -> U,
) -> Self::Result<Entity<U>> {
self.app.insert_model(reservation, build_model)
self.app.insert_entity(reservation, build_model)
}
fn update_model<U: 'static, R>(
fn update_entity<U: 'static, R>(
&mut self,
handle: &Entity<U>,
update: impl FnOnce(&mut U, &mut Context<'_, U>) -> R,
) -> R {
self.app.update_model(handle, update)
self.app.update_entity(handle, update)
}
fn read_model<U, R>(
fn read_entity<U, R>(
&self,
handle: &Entity<U>,
read: impl FnOnce(&U, &App) -> R,
@@ -711,7 +711,7 @@ impl<'a, T> AppContext for Context<'a, T> {
where
U: 'static,
{
self.app.read_model(handle, read)
self.app.read_entity(handle, read)
}
fn update_window<R, F>(&mut self, window: AnyWindowHandle, update: F) -> Result<R>
+23 -23
View File
@@ -1,5 +1,5 @@
use crate::{
Action, AnyView, AnyWindowHandle, App, AppCell, AppContext, AsyncAppContext, AvailableSpace,
Action, AnyView, AnyWindowHandle, App, AppCell, AppContext, AsyncApp, AvailableSpace,
BackgroundExecutor, BorrowAppContext, Bounds, ClipboardItem, DrawPhase, Drawable, Element,
Empty, EventEmitter, ForegroundExecutor, Global, InputEvent, Keystroke, Modifiers,
ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels,
@@ -40,30 +40,30 @@ impl AppContext for TestAppContext {
app.new(build_model)
}
fn reserve_model<T: 'static>(&mut self) -> Self::Result<crate::Reservation<T>> {
fn reserve_entity<T: 'static>(&mut self) -> Self::Result<crate::Reservation<T>> {
let mut app = self.app.borrow_mut();
app.reserve_model()
app.reserve_entity()
}
fn insert_model<T: 'static>(
fn insert_entity<T: 'static>(
&mut self,
reservation: crate::Reservation<T>,
build_model: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Self::Result<Entity<T>> {
let mut app = self.app.borrow_mut();
app.insert_model(reservation, build_model)
app.insert_entity(reservation, build_model)
}
fn update_model<T: 'static, R>(
fn update_entity<T: 'static, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
) -> Self::Result<R> {
let mut app = self.app.borrow_mut();
app.update_model(handle, update)
app.update_entity(handle, update)
}
fn read_model<T, R>(
fn read_entity<T, R>(
&self,
handle: &Entity<T>,
read: impl FnOnce(&T, &App) -> R,
@@ -72,7 +72,7 @@ impl AppContext for TestAppContext {
T: 'static,
{
let app = self.app.borrow();
app.read_model(handle, read)
app.read_entity(handle, read)
}
fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
@@ -302,7 +302,7 @@ impl TestAppContext {
}
/// Run the given task on the main thread.
pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncAppContext) -> Fut) -> Task<R>
pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncApp) -> Fut) -> Task<R>
where
Fut: Future<Output = R> + 'static,
R: 'static,
@@ -341,10 +341,10 @@ impl TestAppContext {
lock.update(|cx| cx.update_global(update))
}
/// Returns an `AsyncAppContext` which can be used to run tasks that expect to be on a background
/// Returns an `AsyncApp` which can be used to run tasks that expect to be on a background
/// thread on the current thread in tests.
pub fn to_async(&self) -> AsyncAppContext {
AsyncAppContext {
pub fn to_async(&self) -> AsyncApp {
AsyncApp {
app: Rc::downgrade(&self.app),
background_executor: self.background_executor.clone(),
foreground_executor: self.foreground_executor.clone(),
@@ -855,19 +855,19 @@ impl AppContext for VisualTestContext {
self.cx.new(build_model)
}
fn reserve_model<T: 'static>(&mut self) -> Self::Result<crate::Reservation<T>> {
self.cx.reserve_model()
fn reserve_entity<T: 'static>(&mut self) -> Self::Result<crate::Reservation<T>> {
self.cx.reserve_entity()
}
fn insert_model<T: 'static>(
fn insert_entity<T: 'static>(
&mut self,
reservation: crate::Reservation<T>,
build_model: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Self::Result<Entity<T>> {
self.cx.insert_model(reservation, build_model)
self.cx.insert_entity(reservation, build_model)
}
fn update_model<T, R>(
fn update_entity<T, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
@@ -875,10 +875,10 @@ impl AppContext for VisualTestContext {
where
T: 'static,
{
self.cx.update_model(handle, update)
self.cx.update_entity(handle, update)
}
fn read_model<T, R>(
fn read_entity<T, R>(
&self,
handle: &Entity<T>,
read: impl FnOnce(&T, &App) -> R,
@@ -886,7 +886,7 @@ impl AppContext for VisualTestContext {
where
T: 'static,
{
self.cx.read_model(handle, read)
self.cx.read_entity(handle, read)
}
fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
@@ -914,7 +914,7 @@ impl VisualContext for VisualTestContext {
self.window
}
fn new_window_model<T: 'static>(
fn new_window_entity<T: 'static>(
&mut self,
build_model: impl FnOnce(&mut Window, &mut Context<'_, T>) -> T,
) -> Self::Result<Entity<T>> {
@@ -925,7 +925,7 @@ impl VisualContext for VisualTestContext {
.unwrap()
}
fn update_window_model<V: 'static, R>(
fn update_window_entity<V: 'static, R>(
&mut self,
view: &Entity<V>,
update: impl FnOnce(&mut V, &mut Window, &mut Context<V>) -> R,
+9 -9
View File
@@ -171,19 +171,19 @@ pub trait AppContext {
/// Reserve a slot for a model to be inserted later.
/// The returned [Reservation] allows you to obtain the [EntityId] for the future model.
fn reserve_model<T: 'static>(&mut self) -> Self::Result<Reservation<T>>;
fn reserve_entity<T: 'static>(&mut self) -> Self::Result<Reservation<T>>;
/// Insert a new model in the app context based on a [Reservation] previously obtained from [`reserve_model`].
/// Insert a new model in the app context based on a [Reservation] previously obtained from [`reserve_entity`].
///
/// [`reserve_model`]: Self::reserve_model
fn insert_model<T: 'static>(
/// [`reserve_entity`]: Self::reserve_entity
fn insert_entity<T: 'static>(
&mut self,
reservation: Reservation<T>,
build_model: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Self::Result<Entity<T>>;
/// Update a model in the app context.
fn update_model<T, R>(
fn update_entity<T, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
@@ -192,7 +192,7 @@ pub trait AppContext {
T: 'static;
/// Read a model from the app context.
fn read_model<T, R>(
fn read_entity<T, R>(
&self,
handle: &Entity<T>,
read: impl FnOnce(&T, &App) -> R,
@@ -215,7 +215,7 @@ pub trait AppContext {
T: 'static;
}
/// Returned by [Context::reserve_model] to later be passed to [Context::insert_model].
/// Returned by [Context::reserve_entity] to later be passed to [Context::insert_model].
/// Allows you to obtain the [EntityId] for a model before it is created.
pub struct Reservation<T>(pub(crate) Slot<T>);
@@ -233,14 +233,14 @@ pub trait VisualContext: AppContext {
fn window_handle(&self) -> AnyWindowHandle;
/// Update a view with the given callback
fn update_window_model<T: 'static, R>(
fn update_window_entity<T: 'static, R>(
&mut self,
model: &Entity<T>,
update: impl FnOnce(&mut T, &mut Window, &mut Context<T>) -> R,
) -> Self::Result<R>;
/// Update a view with the given callback
fn new_window_model<T: 'static>(
fn new_window_entity<T: 'static>(
&mut self,
build_model: impl FnOnce(&mut Window, &mut Context<'_, T>) -> T,
) -> Self::Result<Entity<T>>;
+2 -2
View File
@@ -7,7 +7,7 @@ use std::ops::Range;
/// This input handler can then be assigned during paint by calling [`WindowContext::handle_input`].
///
/// See [`InputHandler`] for details on how to implement each method.
pub trait ViewInputHandler: 'static + Sized {
pub trait EntityInputHandler: 'static + Sized {
/// See [`InputHandler::text_for_range`] for details
fn text_for_range(
&mut self,
@@ -84,7 +84,7 @@ impl<V: 'static> ElementInputHandler<V> {
}
}
impl<V: ViewInputHandler> InputHandler for ElementInputHandler<V> {
impl<V: EntityInputHandler> InputHandler for ElementInputHandler<V> {
fn selected_text_range(
&mut self,
ignore_disabled_input: bool,
+3 -3
View File
@@ -9,12 +9,12 @@
/// actions!(editor,[Undo, Redo]);;
///
/// impl Editor {
/// fn undo(&mut self, _: &Undo, _window: &mut Window, _cx: &mut ModelContext<Self>) { ... }
/// fn redo(&mut self, _: &Redo, _window: &mut Window, _cx: &mut ModelContext<Self>) { ... }
/// fn undo(&mut self, _: &Undo, _window: &mut Window, _cx: &mut Context<Self>) { ... }
/// fn redo(&mut self, _: &Redo, _window: &mut Window, _cx: &mut Context<Self>) { ... }
/// }
///
/// impl Render for Editor {
/// fn render(&mut self, window: &mut Window, cx: &mut ModelContext<Self>) -> impl IntoElement {
/// fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
/// div()
/// .track_focus(&self.focus_handle(cx))
/// .keymap_context("Editor")