Checkpoint

This commit is contained in:
Nathan Sobo 2023-10-31 11:22:40 -06:00
parent 90601fe4fd
commit 9798d65cf9
8 changed files with 51 additions and 51 deletions

View file

@ -28,7 +28,7 @@ pub trait FeatureFlagViewExt<V: 'static> {
F: Fn(bool, &mut V, &mut ViewContext<V>) + Send + Sync + 'static;
}
impl<V> FeatureFlagViewExt<V> for ViewContext<'_, '_, V>
impl<V> FeatureFlagViewExt<V> for ViewContext<'_, V>
where
V: 'static + Send + Sync,
{

View file

@ -308,7 +308,7 @@ impl AppContext {
pub fn update_window_root<V, R>(
&mut self,
handle: &WindowHandle<V>,
update: impl FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> R,
update: impl FnOnce(&mut V, &mut ViewContext<'_, V>) -> R,
) -> Result<R>
where
V: 'static + Send,
@ -882,7 +882,7 @@ impl MainThread<AppContext> {
pub fn update_window_root<V, R>(
&mut self,
handle: &WindowHandle<V>,
update: impl FnOnce(&mut V, &mut MainThread<ViewContext<'_, '_, V>>) -> R,
update: impl FnOnce(&mut V, &mut MainThread<ViewContext<'_, V>>) -> R,
) -> Result<R>
where
V: 'static + Send,

View file

@ -81,7 +81,7 @@ impl AsyncAppContext {
pub fn update_window_root<V, R>(
&mut self,
handle: &WindowHandle<V>,
update: impl FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> R,
update: impl FnOnce(&mut V, &mut ViewContext<'_, V>) -> R,
) -> Result<R>
where
V: 'static + Send,
@ -259,11 +259,11 @@ impl Context for AsyncWindowContext {
}
impl VisualContext for AsyncWindowContext {
type ViewContext<'a, 'w, V: 'static> = ViewContext<'a, 'w, V>;
type ViewContext<'a, V: 'static> = ViewContext<'a, V>;
fn build_view<V>(
&mut self,
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, '_, V>) -> V,
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,
) -> Self::Result<View<V>>
where
V: 'static + Send,
@ -275,7 +275,7 @@ impl VisualContext for AsyncWindowContext {
fn update_view<V: 'static, R>(
&mut self,
view: &View<V>,
update: impl FnOnce(&mut V, &mut Self::ViewContext<'_, '_, V>) -> R,
update: impl FnOnce(&mut V, &mut Self::ViewContext<'_, V>) -> R,
) -> Self::Result<R> {
self.app
.update_window(self.window, |cx| cx.update_view(view, update))

View file

@ -221,7 +221,7 @@ impl<V, E, F> Element<V> for Option<F>
where
V: 'static,
E: 'static + Component<V> + Send,
F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + 'static,
F: FnOnce(&mut V, &mut ViewContext<'_, V>) -> E + Send + 'static,
{
type ElementState = AnyElement<V>;
@ -265,7 +265,7 @@ impl<V, E, F> Component<V> for Option<F>
where
V: 'static,
E: 'static + Component<V> + Send,
F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + 'static,
F: FnOnce(&mut V, &mut ViewContext<'_, V>) -> E + Send + 'static,
{
fn render(self) -> AnyElement<V> {
AnyElement::new(self)
@ -276,7 +276,7 @@ impl<V, E, F> Component<V> for F
where
V: 'static,
E: 'static + Component<V> + Send,
F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + 'static,
F: FnOnce(&mut V, &mut ViewContext<'_, V>) -> E + Send + 'static,
{
fn render(self) -> AnyElement<V> {
AnyElement::new(Some(self))

View file

@ -95,11 +95,11 @@ pub trait Context {
}
pub trait VisualContext: Context {
type ViewContext<'a, 'w, V: 'static>;
type ViewContext<'a, V: 'static>;
fn build_view<V>(
&mut self,
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, '_, V>) -> V,
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,
) -> Self::Result<View<V>>
where
V: 'static + Send;
@ -107,7 +107,7 @@ pub trait VisualContext: Context {
fn update_view<V: 'static, R>(
&mut self,
view: &View<V>,
update: impl FnOnce(&mut V, &mut Self::ViewContext<'_, '_, V>) -> R,
update: impl FnOnce(&mut V, &mut Self::ViewContext<'_, V>) -> R,
) -> Self::Result<R>;
}
@ -184,11 +184,11 @@ impl<C: Context> Context for MainThread<C> {
}
impl<C: VisualContext> VisualContext for MainThread<C> {
type ViewContext<'a, 'w, V: 'static> = MainThread<C::ViewContext<'a, 'w, V>>;
type ViewContext<'a, V: 'static> = MainThread<C::ViewContext<'a, V>>;
fn build_view<V>(
&mut self,
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, '_, V>) -> V,
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,
) -> Self::Result<View<V>>
where
V: 'static + Send,
@ -196,8 +196,8 @@ impl<C: VisualContext> VisualContext for MainThread<C> {
self.0.build_view(|cx| {
let cx = unsafe {
mem::transmute::<
&mut C::ViewContext<'_, '_, V>,
&mut MainThread<C::ViewContext<'_, '_, V>>,
&mut C::ViewContext<'_, V>,
&mut MainThread<C::ViewContext<'_, V>>,
>(cx)
};
build_view_state(cx)
@ -207,13 +207,13 @@ impl<C: VisualContext> VisualContext for MainThread<C> {
fn update_view<V: 'static, R>(
&mut self,
view: &View<V>,
update: impl FnOnce(&mut V, &mut Self::ViewContext<'_, '_, V>) -> R,
update: impl FnOnce(&mut V, &mut Self::ViewContext<'_, V>) -> R,
) -> Self::Result<R> {
self.0.update_view(view, |view_state, cx| {
let cx = unsafe {
mem::transmute::<
&mut C::ViewContext<'_, '_, V>,
&mut MainThread<C::ViewContext<'_, '_, V>>,
&mut C::ViewContext<'_, V>,
&mut MainThread<C::ViewContext<'_, V>>,
>(cx)
};
update(view_state, cx)

View file

@ -53,7 +53,7 @@ impl<V: 'static> View<V> {
pub fn update<C, R>(
&self,
cx: &mut C,
f: impl FnOnce(&mut V, &mut C::ViewContext<'_, '_, V>) -> R,
f: impl FnOnce(&mut V, &mut C::ViewContext<'_, V>) -> R,
) -> C::Result<R>
where
C: VisualContext,
@ -152,7 +152,7 @@ impl<V: 'static> WeakView<V> {
pub fn update<C, R>(
&self,
cx: &mut C,
f: impl FnOnce(&mut V, &mut C::ViewContext<'_, '_, V>) -> R,
f: impl FnOnce(&mut V, &mut C::ViewContext<'_, V>) -> R,
) -> Result<R>
where
C: VisualContext,

View file

@ -1305,11 +1305,11 @@ impl Context for WindowContext<'_, '_> {
}
impl VisualContext for WindowContext<'_, '_> {
type ViewContext<'a, 'w, V: 'static> = ViewContext<'a, 'w, V>;
type ViewContext<'a, V: 'static> = ViewContext<'a, V>;
fn build_view<V>(
&mut self,
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, '_, V>) -> V,
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,
) -> Self::Result<View<V>>
where
V: 'static + Send,
@ -1328,7 +1328,7 @@ impl VisualContext for WindowContext<'_, '_> {
fn update_view<T: 'static, R>(
&mut self,
view: &View<T>,
update: impl FnOnce(&mut T, &mut Self::ViewContext<'_, '_, T>) -> R,
update: impl FnOnce(&mut T, &mut Self::ViewContext<'_, T>) -> R,
) -> Self::Result<R> {
let mut lease = self.app.entities.lease(&view.model);
let mut cx = ViewContext::new(&mut *self.app, &mut *self.window, &view);
@ -1540,37 +1540,37 @@ impl BorrowMut<Window> for WindowContext<'_, '_> {
impl<T> BorrowWindow for T where T: BorrowMut<AppContext> + BorrowMut<Window> {}
pub struct ViewContext<'a, 'w, V> {
window_cx: WindowContext<'a, 'w>,
view: &'w View<V>,
pub struct ViewContext<'a, V> {
window_cx: WindowContext<'a, 'a>,
view: &'a View<V>,
}
impl<V> Borrow<AppContext> for ViewContext<'_, '_, V> {
impl<V> Borrow<AppContext> for ViewContext<'_, V> {
fn borrow(&self) -> &AppContext {
&*self.window_cx.app
}
}
impl<V> BorrowMut<AppContext> for ViewContext<'_, '_, V> {
impl<V> BorrowMut<AppContext> for ViewContext<'_, V> {
fn borrow_mut(&mut self) -> &mut AppContext {
&mut *self.window_cx.app
}
}
impl<V> Borrow<Window> for ViewContext<'_, '_, V> {
impl<V> Borrow<Window> for ViewContext<'_, V> {
fn borrow(&self) -> &Window {
&*self.window_cx.window
}
}
impl<V> BorrowMut<Window> for ViewContext<'_, '_, V> {
impl<V> BorrowMut<Window> for ViewContext<'_, V> {
fn borrow_mut(&mut self) -> &mut Window {
&mut *self.window_cx.window
}
}
impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> {
pub(crate) fn new(app: &'a mut AppContext, window: &'w mut Window, view: &'w View<V>) -> Self {
impl<'a, V: 'static> ViewContext<'a, V> {
pub(crate) fn new(app: &'a mut AppContext, window: &'a mut Window, view: &'a View<V>) -> Self {
Self {
window_cx: WindowContext::mutable(app, window),
view,
@ -1612,7 +1612,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> {
pub fn observe<V2, E>(
&mut self,
entity: &E,
mut on_notify: impl FnMut(&mut V, E, &mut ViewContext<'_, '_, V>) + Send + 'static,
mut on_notify: impl FnMut(&mut V, E, &mut ViewContext<'_, V>) + Send + 'static,
) -> Subscription
where
V2: 'static,
@ -1642,7 +1642,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> {
pub fn subscribe<V2, E>(
&mut self,
entity: &E,
mut on_event: impl FnMut(&mut V, E, &V2::Event, &mut ViewContext<'_, '_, V>) + Send + 'static,
mut on_event: impl FnMut(&mut V, E, &V2::Event, &mut ViewContext<'_, V>) + Send + 'static,
) -> Subscription
where
V2: EventEmitter,
@ -1687,7 +1687,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> {
pub fn observe_release<V2, E>(
&mut self,
entity: &E,
mut on_release: impl FnMut(&mut V, &mut V2, &mut ViewContext<'_, '_, V>) + Send + 'static,
mut on_release: impl FnMut(&mut V, &mut V2, &mut ViewContext<'_, V>) + Send + 'static,
) -> Subscription
where
V: Any + Send,
@ -1816,7 +1816,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> {
pub fn run_on_main<R>(
&mut self,
view: &mut V,
f: impl FnOnce(&mut V, &mut MainThread<ViewContext<'_, '_, V>>) -> R + Send + 'static,
f: impl FnOnce(&mut V, &mut MainThread<ViewContext<'_, V>>) -> R + Send + 'static,
) -> Task<Result<R>>
where
R: Send + 'static,
@ -1857,7 +1857,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> {
pub fn observe_global<G: 'static>(
&mut self,
f: impl Fn(&mut V, &mut ViewContext<'_, '_, V>) + Send + 'static,
f: impl Fn(&mut V, &mut ViewContext<'_, V>) + Send + 'static,
) -> Subscription {
let window_handle = self.window.handle;
let view = self.view().downgrade();
@ -1885,10 +1885,10 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> {
}
}
impl<'a, 'w, V> ViewContext<'a, 'w, V>
impl<V> ViewContext<'_, V>
where
V: EventEmitter,
V::Event: Any + Send,
V::Event: 'static + Send,
{
pub fn emit(&mut self, event: V::Event) {
let emitter = self.view.model.entity_id;
@ -1899,7 +1899,7 @@ where
}
}
impl<'a, 'w, V: 'static> MainThread<ViewContext<'a, 'w, V>> {
impl<V: 'static> MainThread<ViewContext<'_, V>> {
fn platform_window(&self) -> &dyn PlatformWindow {
self.window.platform_window.borrow_on_main_thread().as_ref()
}
@ -1909,7 +1909,7 @@ impl<'a, 'w, V: 'static> MainThread<ViewContext<'a, 'w, V>> {
}
}
impl<'a, 'w, V> Context for ViewContext<'a, 'w, V> {
impl<V> Context for ViewContext<'_, V> {
type ModelContext<'b, U> = ModelContext<'b, U>;
type Result<U> = U;
@ -1932,12 +1932,12 @@ impl<'a, 'w, V> Context for ViewContext<'a, 'w, V> {
}
}
impl<V: 'static> VisualContext for ViewContext<'_, '_, V> {
type ViewContext<'a, 'w, V2: 'static> = ViewContext<'a, 'w, V2>;
impl<V: 'static> VisualContext for ViewContext<'_, V> {
type ViewContext<'a, W: 'static> = ViewContext<'a, W>;
fn build_view<W: 'static + Send>(
&mut self,
build_view: impl FnOnce(&mut Self::ViewContext<'_, '_, W>) -> W,
build_view: impl FnOnce(&mut Self::ViewContext<'_, W>) -> W,
) -> Self::Result<View<W>> {
self.window_cx.build_view(build_view)
}
@ -1945,21 +1945,21 @@ impl<V: 'static> VisualContext for ViewContext<'_, '_, V> {
fn update_view<V2: 'static, R>(
&mut self,
view: &View<V2>,
update: impl FnOnce(&mut V2, &mut Self::ViewContext<'_, '_, V2>) -> R,
update: impl FnOnce(&mut V2, &mut Self::ViewContext<'_, V2>) -> R,
) -> Self::Result<R> {
self.window_cx.update_view(view, update)
}
}
impl<'a, 'w, V> std::ops::Deref for ViewContext<'a, 'w, V> {
type Target = WindowContext<'a, 'w>;
impl<'a, V> std::ops::Deref for ViewContext<'a, V> {
type Target = WindowContext<'a, 'a>;
fn deref(&self) -> &Self::Target {
&self.window_cx
}
}
impl<'a, 'w, V> std::ops::DerefMut for ViewContext<'a, 'w, V> {
impl<'a, V> std::ops::DerefMut for ViewContext<'a, V> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.window_cx
}

View file

@ -30,7 +30,7 @@ pub fn derive_component(input: TokenStream) -> TokenStream {
let expanded = quote! {
impl #impl_generics gpui2::Component<#view_type> for #name #ty_generics #where_clause {
fn render(self) -> gpui2::AnyElement<#view_type> {
(move |view_state: &mut #view_type, cx: &mut gpui2::ViewContext<'_, '_, #view_type>| self.render(view_state, cx))
(move |view_state: &mut #view_type, cx: &mut gpui2::ViewContext<'_, #view_type>| self.render(view_state, cx))
.render()
}
}