mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-30 22:34:13 +00:00
Checkpoint
This commit is contained in:
parent
cae5c76bed
commit
faabed1df0
1 changed files with 39 additions and 44 deletions
|
@ -35,22 +35,6 @@ impl AppContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_entity<T: 'static, R>(
|
|
||||||
&mut self,
|
|
||||||
handle: &Handle<T>,
|
|
||||||
update: impl FnOnce(&mut T, &mut ModelContext<T>) -> R,
|
|
||||||
) -> R {
|
|
||||||
let mut entity = self
|
|
||||||
.entities
|
|
||||||
.remove(&handle.id)
|
|
||||||
.unwrap()
|
|
||||||
.downcast::<T>()
|
|
||||||
.unwrap();
|
|
||||||
let result = update(&mut *entity, &mut ModelContext::mutable(self, handle.id));
|
|
||||||
self.entities.insert(handle.id, Box::new(entity));
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_window<R>(
|
fn update_window<R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
window_id: WindowId,
|
window_id: WindowId,
|
||||||
|
@ -213,50 +197,61 @@ pub struct Handle<T> {
|
||||||
entity_type: PhantomData<T>,
|
entity_type: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
trait Context<'a, 'parent, 'app, 'win> {
|
trait Context {
|
||||||
type EntityContext<T: 'static>;
|
type EntityContext<'cx, 'app, 'win, T: 'static>;
|
||||||
|
|
||||||
fn update_entity<T: 'static, R>(
|
fn update_entity<'a, 'app, 'win, T: 'static, R>(
|
||||||
&mut self,
|
&'a mut self,
|
||||||
handle: &Handle<T>,
|
handle: &Handle<T>,
|
||||||
update: impl FnOnce(&mut T, Self::EntityContext<T>) -> R,
|
update: impl for<'cx> FnOnce(&mut T, &mut Self::EntityContext<'cx, 'app, 'win, T>) -> R,
|
||||||
) -> R;
|
) -> R;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'parent: 'a, 'app, 'win> Context<'a, 'parent, 'app, 'win> for AppContext {
|
impl Context for AppContext {
|
||||||
type EntityContext<T: 'static> = &'a mut ModelContext<'parent, T>;
|
type EntityContext<'cx, 'app, 'win, T: 'static> = ModelContext<'cx, T>;
|
||||||
|
|
||||||
fn update_entity<T: 'static, R>(
|
fn update_entity<'a, 'app, 'win, T: 'static, R>(
|
||||||
&mut self,
|
&'a mut self,
|
||||||
handle: &Handle<T>,
|
handle: &Handle<T>,
|
||||||
update: impl FnOnce(&mut T, Self::EntityContext<T>) -> R,
|
update: impl FnOnce(&mut T, &mut Self::EntityContext<'_, 'app, 'win, T>) -> R,
|
||||||
) -> R {
|
) -> R {
|
||||||
todo!()
|
let mut entity = self
|
||||||
|
.entities
|
||||||
|
.remove(&handle.id)
|
||||||
|
.unwrap()
|
||||||
|
.downcast::<T>()
|
||||||
|
.unwrap();
|
||||||
|
let result = update(&mut *entity, &mut ModelContext::mutable(self, handle.id));
|
||||||
|
self.entities.insert(handle.id, Box::new(entity));
|
||||||
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'parent, 'app, 'win> Context<'a, 'parent, 'app, 'win> for WindowContext<'app, 'win>
|
// impl<'app, 'win> Context for WindowContext<'app, 'win> {
|
||||||
where
|
// type EntityContext<'cx, 'app, 'win, T: 'static> = ModelContext<'cx, T>;
|
||||||
'parent: 'a,
|
|
||||||
'app: 'parent,
|
|
||||||
'win: 'parent,
|
|
||||||
{
|
|
||||||
type EntityContext<T: 'static> = &'a mut ViewContext<'parent, 'app, 'win, T>;
|
|
||||||
|
|
||||||
fn update_entity<T: 'static, R>(
|
// fn update_entity<'a, 'app, 'win, T: 'static, R>(
|
||||||
&mut self,
|
// &'a mut self,
|
||||||
handle: &Handle<T>,
|
// handle: &Handle<T>,
|
||||||
update: impl FnOnce(&mut T, Self::EntityContext<T>) -> R,
|
// update: impl FnOnce(&mut T, &mut Self::EntityContext<'_, 'app, 'win, T>) -> R,
|
||||||
) -> R {
|
// ) -> R {
|
||||||
todo!()
|
// let mut entity = self
|
||||||
}
|
// .entities
|
||||||
}
|
// .remove(&handle.id)
|
||||||
|
// .unwrap()
|
||||||
|
// .downcast::<T>()
|
||||||
|
// .unwrap();
|
||||||
|
// let result = update(&mut *entity, &mut ModelContext::mutable(self, handle.id));
|
||||||
|
// self.entities.insert(handle.id, Box::new(entity));
|
||||||
|
// result
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
impl<T: 'static> Handle<T> {
|
impl<T: 'static> Handle<T> {
|
||||||
fn update<'a, 'parent, 'app, 'win, C: Context<'a, 'parent, 'app, 'win>, R>(
|
fn update<'app, 'win, C: Context, R>(
|
||||||
&self,
|
&self,
|
||||||
cx: &mut C,
|
cx: &mut C,
|
||||||
update: impl FnOnce(&mut T, C::EntityContext<T>) -> R,
|
update: impl FnOnce(&mut T, &mut C::EntityContext<'_, 'app, 'win, T>) -> R,
|
||||||
) -> R {
|
) -> R {
|
||||||
cx.update_entity(self, update)
|
cx.update_entity(self, update)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue