diff --git a/crates/call/src/room.rs b/crates/call/src/room.rs index 4e52f57f60..a3cd71c523 100644 --- a/crates/call/src/room.rs +++ b/crates/call/src/room.rs @@ -1251,7 +1251,7 @@ impl Room { .read_with(&cx, |this, _| { this.live_kit .as_ref() - .map(|live_kit| live_kit.room.publish_audio_track(&track)) + .map(|live_kit| live_kit.room.publish_audio_track(track)) }) .ok_or_else(|| anyhow!("live-kit was not initialized"))? .await @@ -1337,7 +1337,7 @@ impl Room { .read_with(&cx, |this, _| { this.live_kit .as_ref() - .map(|live_kit| live_kit.room.publish_video_track(&track)) + .map(|live_kit| live_kit.room.publish_video_track(track)) }) .ok_or_else(|| anyhow!("live-kit was not initialized"))? .await @@ -1481,11 +1481,12 @@ impl Room { #[cfg(any(test, feature = "test-support"))] pub fn set_display_sources(&self, sources: Vec) { - self.live_kit - .as_ref() - .unwrap() - .room - .set_display_sources(sources); + todo!() + // self.live_kit + // .as_ref() + // .unwrap() + // .room + // .set_display_sources(sources); } } diff --git a/crates/call2/src/room.rs b/crates/call2/src/room.rs index 091ff17029..9aa91153d3 100644 --- a/crates/call2/src/room.rs +++ b/crates/call2/src/room.rs @@ -1269,7 +1269,7 @@ impl Room { .update(&mut cx, |this, _| { this.live_kit .as_ref() - .map(|live_kit| live_kit.room.publish_audio_track(&track)) + .map(|live_kit| live_kit.room.publish_audio_track(track)) })? .ok_or_else(|| anyhow!("live-kit was not initialized"))? .await @@ -1355,7 +1355,7 @@ impl Room { .update(&mut cx, |this, _| { this.live_kit .as_ref() - .map(|live_kit| live_kit.room.publish_video_track(&track)) + .map(|live_kit| live_kit.room.publish_video_track(track)) })? .ok_or_else(|| anyhow!("live-kit was not initialized"))? .await diff --git a/crates/client2/src/client2.rs b/crates/client2/src/client2.rs index 79b0205c91..8eaf248521 100644 --- a/crates/client2/src/client2.rs +++ b/crates/client2/src/client2.rs @@ -312,7 +312,7 @@ pub struct PendingEntitySubscription { impl PendingEntitySubscription where - T: 'static + Send + Sync, + T: 'static + Send, { pub fn set_model(mut self, model: &Handle, cx: &mut AsyncAppContext) -> Subscription { self.consumed = true; @@ -529,7 +529,7 @@ impl Client { remote_id: u64, ) -> Result> where - T: 'static + Send + Sync, + T: 'static + Send, { let id = (TypeId::of::(), remote_id); @@ -557,7 +557,7 @@ impl Client { ) -> Subscription where M: EnvelopedMessage, - E: 'static + Send + Sync, + E: 'static + Send, H: 'static + Send + Sync + Fn(Handle, TypedEnvelope, Arc, AsyncAppContext) -> F, F: 'static + Future> + Send, { @@ -599,7 +599,7 @@ impl Client { ) -> Subscription where M: RequestMessage, - E: 'static + Send + Sync, + E: 'static + Send, H: 'static + Send + Sync + Fn(Handle, TypedEnvelope, Arc, AsyncAppContext) -> F, F: 'static + Future> + Send, { @@ -615,7 +615,7 @@ impl Client { pub fn add_model_message_handler(self: &Arc, handler: H) where M: EntityMessage, - E: 'static + Send + Sync, + E: 'static + Send, H: 'static + Send + Sync + Fn(Handle, TypedEnvelope, Arc, AsyncAppContext) -> F, F: 'static + Future> + Send, { @@ -627,7 +627,7 @@ impl Client { fn add_entity_message_handler(self: &Arc, handler: H) where M: EntityMessage, - E: 'static + Send + Sync, + E: 'static + Send, H: 'static + Send + Sync + Fn(AnyHandle, TypedEnvelope, Arc, AsyncAppContext) -> F, F: 'static + Future> + Send, { @@ -666,7 +666,7 @@ impl Client { pub fn add_model_request_handler(self: &Arc, handler: H) where M: EntityMessage + RequestMessage, - E: 'static + Send + Sync, + E: 'static + Send, H: 'static + Send + Sync + Fn(Handle, TypedEnvelope, Arc, AsyncAppContext) -> F, F: 'static + Future> + Send, { diff --git a/crates/gpui2/src/action.rs b/crates/gpui2/src/action.rs index b6420c2b82..638e5c6ca3 100644 --- a/crates/gpui2/src/action.rs +++ b/crates/gpui2/src/action.rs @@ -4,7 +4,7 @@ use collections::{HashMap, HashSet}; use serde::Deserialize; use std::any::{type_name, Any}; -pub trait Action: Any + Send + Sync { +pub trait Action: Any + Send { fn qualified_name() -> SharedString where Self: Sized; @@ -19,7 +19,7 @@ pub trait Action: Any + Send + Sync { impl Action for A where - A: for<'a> Deserialize<'a> + PartialEq + Any + Send + Sync + Clone + Default, + A: for<'a> Deserialize<'a> + PartialEq + Any + Send + Clone + Default, { fn qualified_name() -> SharedString { type_name::().into() diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rs index 35efe84e48..9e96e5a437 100644 --- a/crates/gpui2/src/app.rs +++ b/crates/gpui2/src/app.rs @@ -22,7 +22,7 @@ use crate::{ use anyhow::{anyhow, Result}; use collections::{HashMap, HashSet, VecDeque}; use futures::{future::BoxFuture, Future}; -use parking_lot::{Mutex, RwLock}; +use parking_lot::Mutex; use slotmap::SlotMap; use std::{ any::{type_name, Any, TypeId}, @@ -109,11 +109,10 @@ impl App { type ActionBuilder = fn(json: Option) -> anyhow::Result>; type FrameCallback = Box; -type Handler = Box bool + Send + Sync + 'static>; -type Listener = Box bool + Send + Sync + 'static>; -type QuitHandler = - Box BoxFuture<'static, ()> + Send + Sync + 'static>; -type ReleaseListener = Box; +type Handler = Box bool + Send + 'static>; +type Listener = Box bool + Send + 'static>; +type QuitHandler = Box BoxFuture<'static, ()> + Send + 'static>; +type ReleaseListener = Box; pub struct AppContext { this: Weak>, @@ -133,9 +132,9 @@ pub struct AppContext { pub(crate) unit_entity: Handle<()>, pub(crate) entities: EntityMap, pub(crate) windows: SlotMap>, - pub(crate) keymap: Arc>, + pub(crate) keymap: Arc>, pub(crate) global_action_listeners: - HashMap>>, + HashMap>>, action_builders: HashMap, pending_effects: VecDeque, pub(crate) pending_notifications: HashSet, @@ -188,7 +187,7 @@ impl AppContext { unit_entity, entities, windows: SlotMap::with_key(), - keymap: Arc::new(RwLock::new(Keymap::default())), + keymap: Arc::new(Mutex::new(Keymap::default())), global_action_listeners: HashMap::default(), action_builders: HashMap::default(), pending_effects: VecDeque::new(), @@ -447,7 +446,7 @@ impl AppContext { .retain(&type_id, |observer| observer(self)); } - fn apply_defer_effect(&mut self, callback: Box) { + fn apply_defer_effect(&mut self, callback: Box) { callback(self); } @@ -506,7 +505,7 @@ impl AppContext { }) } - pub fn defer(&mut self, f: impl FnOnce(&mut AppContext) + 'static + Send + Sync) { + pub fn defer(&mut self, f: impl FnOnce(&mut AppContext) + 'static + Send) { self.push_effect(Effect::Defer { callback: Box::new(f), }); @@ -556,7 +555,7 @@ impl AppContext { .unwrap() } - pub fn default_global(&mut self) -> &mut G { + pub fn default_global(&mut self) -> &mut G { let global_type = TypeId::of::(); self.push_effect(Effect::NotifyGlobalObservers { global_type }); self.globals_by_type @@ -566,7 +565,7 @@ impl AppContext { .unwrap() } - pub fn set_global(&mut self, global: G) { + pub fn set_global(&mut self, global: G) { let global_type = TypeId::of::(); self.push_effect(Effect::NotifyGlobalObservers { global_type }); self.globals_by_type.insert(global_type, Box::new(global)); @@ -581,7 +580,7 @@ impl AppContext { pub fn observe_global( &mut self, - mut f: impl FnMut(&mut Self) + Send + Sync + 'static, + mut f: impl FnMut(&mut Self) + Send + 'static, ) -> Subscription { self.global_observers.insert( TypeId::of::(), @@ -616,14 +615,11 @@ impl AppContext { } pub fn bind_keys(&mut self, bindings: impl IntoIterator) { - self.keymap.write().add_bindings(bindings); + self.keymap.lock().add_bindings(bindings); self.pending_effects.push_back(Effect::Refresh); } - pub fn on_action( - &mut self, - listener: impl Fn(&A, &mut Self) + Send + Sync + 'static, - ) { + pub fn on_action(&mut self, listener: impl Fn(&A, &mut Self) + Send + 'static) { self.global_action_listeners .entry(TypeId::of::()) .or_default() @@ -660,7 +656,7 @@ impl Context for AppContext { type EntityContext<'a, 'w, T> = ModelContext<'a, T>; type Result = T; - fn entity( + fn entity( &mut self, build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, T>) -> T, ) -> Handle { @@ -766,7 +762,7 @@ impl MainThread { }) } - pub fn update_global( + pub fn update_global( &mut self, update: impl FnOnce(&mut G, &mut MainThread) -> R, ) -> R { @@ -783,7 +779,7 @@ pub(crate) enum Effect { }, Emit { emitter: EntityId, - event: Box, + event: Box, }, FocusChanged { window_id: WindowId, @@ -794,7 +790,7 @@ pub(crate) enum Effect { global_type: TypeId, }, Defer { - callback: Box, + callback: Box, }, } diff --git a/crates/gpui2/src/app/async_context.rs b/crates/gpui2/src/app/async_context.rs index 42c9e96dd0..32b44dd413 100644 --- a/crates/gpui2/src/app/async_context.rs +++ b/crates/gpui2/src/app/async_context.rs @@ -5,7 +5,7 @@ use crate::{ use anyhow::anyhow; use derive_more::{Deref, DerefMut}; use parking_lot::Mutex; -use std::{any::Any, future::Future, sync::Weak}; +use std::{future::Future, sync::Weak}; #[derive(Clone)] pub struct AsyncAppContext { @@ -22,7 +22,7 @@ impl Context for AsyncAppContext { build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, T>) -> T, ) -> Self::Result> where - T: Any + Send + Sync, + T: 'static + Send, { let app = self .app @@ -224,7 +224,7 @@ impl Context for AsyncWindowContext { build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, T>) -> T, ) -> Result> where - T: Any + Send + Sync, + T: 'static + Send, { self.app .update_window(self.window, |cx| cx.entity(build_entity)) diff --git a/crates/gpui2/src/app/entity_map.rs b/crates/gpui2/src/app/entity_map.rs index 0420517590..be50fabc10 100644 --- a/crates/gpui2/src/app/entity_map.rs +++ b/crates/gpui2/src/app/entity_map.rs @@ -4,7 +4,7 @@ use derive_more::{Deref, DerefMut}; use parking_lot::{RwLock, RwLockUpgradableReadGuard}; use slotmap::{SecondaryMap, SlotMap}; use std::{ - any::{type_name, Any, TypeId}, + any::{type_name, TypeId}, fmt::{self, Display}, hash::{Hash, Hasher}, marker::PhantomData, @@ -59,7 +59,7 @@ impl EntityMap { /// Insert an entity into a slot obtained by calling `reserve`. pub fn insert(&mut self, slot: Slot, entity: T) -> Handle where - T: Any + Send + Sync, + T: 'static + Send, { let handle = slot.0; self.entities.insert(handle.entity_id, Box::new(entity)); diff --git a/crates/gpui2/src/app/model_context.rs b/crates/gpui2/src/app/model_context.rs index d81b113b7b..97a9c30721 100644 --- a/crates/gpui2/src/app/model_context.rs +++ b/crates/gpui2/src/app/model_context.rs @@ -43,10 +43,10 @@ impl<'a, T: 'static> ModelContext<'a, T> { pub fn observe( &mut self, handle: &Handle, - mut on_notify: impl FnMut(&mut T, Handle, &mut ModelContext<'_, T>) + Send + Sync + 'static, + mut on_notify: impl FnMut(&mut T, Handle, &mut ModelContext<'_, T>) + Send + 'static, ) -> Subscription where - T: Any + Send + Sync, + T: 'static + Send, { let this = self.weak_handle(); let handle = handle.downgrade(); @@ -68,11 +68,10 @@ impl<'a, T: 'static> ModelContext<'a, T> { handle: &Handle, mut on_event: impl FnMut(&mut T, Handle, &E::Event, &mut ModelContext<'_, T>) + Send - + Sync + 'static, ) -> Subscription where - T: Any + Send + Sync, + T: 'static + Send, { let this = self.weak_handle(); let handle = handle.downgrade(); @@ -92,7 +91,7 @@ impl<'a, T: 'static> ModelContext<'a, T> { pub fn on_release( &mut self, - mut on_release: impl FnMut(&mut T, &mut AppContext) + Send + Sync + 'static, + mut on_release: impl FnMut(&mut T, &mut AppContext) + Send + 'static, ) -> Subscription where T: 'static, @@ -109,10 +108,10 @@ impl<'a, T: 'static> ModelContext<'a, T> { pub fn observe_release( &mut self, handle: &Handle, - mut on_release: impl FnMut(&mut T, &mut E, &mut ModelContext<'_, T>) + Send + Sync + 'static, + mut on_release: impl FnMut(&mut T, &mut E, &mut ModelContext<'_, T>) + Send + 'static, ) -> Subscription where - T: Any + Send + Sync, + T: Any + Send, { let this = self.weak_handle(); self.app.release_listeners.insert( @@ -128,10 +127,10 @@ impl<'a, T: 'static> ModelContext<'a, T> { pub fn observe_global( &mut self, - mut f: impl FnMut(&mut T, &mut ModelContext<'_, T>) + Send + Sync + 'static, + mut f: impl FnMut(&mut T, &mut ModelContext<'_, T>) + Send + 'static, ) -> Subscription where - T: Any + Send + Sync, + T: 'static + Send, { let handle = self.weak_handle(); self.global_observers.insert( @@ -142,11 +141,11 @@ impl<'a, T: 'static> ModelContext<'a, T> { pub fn on_app_quit( &mut self, - mut on_quit: impl FnMut(&mut T, &mut ModelContext) -> Fut + Send + Sync + 'static, + mut on_quit: impl FnMut(&mut T, &mut ModelContext) -> Fut + Send + 'static, ) -> Subscription where Fut: 'static + Future + Send, - T: Any + Send + Sync, + T: 'static + Send, { let handle = self.weak_handle(); self.app.quit_observers.insert( @@ -177,7 +176,7 @@ impl<'a, T: 'static> ModelContext<'a, T> { pub fn update_global(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R where - G: 'static + Send + Sync, + G: 'static + Send, { let mut global = self.app.lease_global::(); let result = f(&mut global, self); @@ -214,7 +213,7 @@ impl<'a, T: 'static> ModelContext<'a, T> { impl<'a, T> ModelContext<'a, T> where T: EventEmitter, - T::Event: Send + Sync, + T::Event: Send, { pub fn emit(&mut self, event: T::Event) { self.app.pending_effects.push_back(Effect::Emit { @@ -233,7 +232,7 @@ impl<'a, T> Context for ModelContext<'a, T> { build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, U>) -> U, ) -> Handle where - U: 'static + Send + Sync, + U: 'static + Send, { self.app.entity(build_entity) } diff --git a/crates/gpui2/src/app/test_context.rs b/crates/gpui2/src/app/test_context.rs index 274121b692..5793ebc9ad 100644 --- a/crates/gpui2/src/app/test_context.rs +++ b/crates/gpui2/src/app/test_context.rs @@ -3,7 +3,7 @@ use crate::{ ModelContext, Result, Task, TestDispatcher, TestPlatform, WindowContext, }; use parking_lot::Mutex; -use std::{any::Any, future::Future, sync::Arc}; +use std::{future::Future, sync::Arc}; #[derive(Clone)] pub struct TestAppContext { @@ -20,7 +20,7 @@ impl Context for TestAppContext { build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, T>) -> T, ) -> Self::Result> where - T: Any + Send + Sync, + T: 'static + Send, { let mut lock = self.app.lock(); lock.entity(build_entity) diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index 15d29a7c42..6dc5bc0a93 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -16,8 +16,6 @@ pub trait Element { element_state: Option, cx: &mut ViewContext, ) -> Self::ElementState; - // where - // V: Any + Send + Sync; fn layout( &mut self, @@ -25,8 +23,6 @@ pub trait Element { element_state: &mut Self::ElementState, cx: &mut ViewContext, ) -> LayoutId; - // where - // V: Any + Send + Sync; fn paint( &mut self, @@ -35,9 +31,6 @@ pub trait Element { element_state: &mut Self::ElementState, cx: &mut ViewContext, ); - - // where - // Self::ViewState: Any + Send + Sync; } #[derive(Deref, DerefMut, Default, Clone, Debug, Eq, PartialEq, Hash)] @@ -104,8 +97,7 @@ impl> RenderedElement { impl ElementObject for RenderedElement where E: Element, - // E::ViewState: Any + Send + Sync, - E::ElementState: Any + Send + Sync, + E::ElementState: 'static + Send, { fn initialize(&mut self, view_state: &mut V, cx: &mut ViewContext) { let frame_state = if let Some(id) = self.element.id() { @@ -178,18 +170,16 @@ where } } -pub struct AnyElement(Box + Send + Sync>); +pub struct AnyElement(Box + Send>); unsafe impl Send for AnyElement {} -unsafe impl Sync for AnyElement {} impl AnyElement { pub fn new(element: E) -> Self where V: 'static, - E: 'static + Send + Sync, - E: Element, - E::ElementState: Any + Send + Sync, + E: 'static + Element + Send, + E::ElementState: Any + Send, { AnyElement(Box::new(RenderedElement::new(element))) } @@ -230,8 +220,8 @@ impl Component for AnyElement { impl Element for Option where V: 'static, - E: 'static + Component + Send + Sync, - F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, + E: 'static + Component + Send, + F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + 'static, { type ElementState = AnyElement; @@ -274,8 +264,8 @@ where impl Component for Option where V: 'static, - E: 'static + Component + Send + Sync, - F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, + E: 'static + Component + Send, + F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + 'static, { fn render(self) -> AnyElement { AnyElement::new(self) @@ -285,8 +275,8 @@ where impl Component for F where V: 'static, - E: 'static + Component + Send + Sync, - F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, + E: 'static + Component + Send, + F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + 'static, { fn render(self) -> AnyElement { AnyElement::new(Some(self)) diff --git a/crates/gpui2/src/focusable.rs b/crates/gpui2/src/focusable.rs index c283998ca2..d7cfc5fe8f 100644 --- a/crates/gpui2/src/focusable.rs +++ b/crates/gpui2/src/focusable.rs @@ -4,12 +4,11 @@ use crate::{ }; use refineable::Refineable; use smallvec::SmallVec; -use std::sync::Arc; pub type FocusListeners = SmallVec<[FocusListener; 2]>; pub type FocusListener = - Arc) + Send + Sync + 'static>; + Box) + Send + 'static>; pub trait Focusable: Element { fn focus_listeners(&mut self) -> &mut FocusListeners; @@ -43,13 +42,13 @@ pub trait Focusable: Element { fn on_focus( mut self, - listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext) + Send + Sync + 'static, + listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.focus_listeners() - .push(Arc::new(move |view, focus_handle, event, cx| { + .push(Box::new(move |view, focus_handle, event, cx| { if event.focused.as_ref() == Some(focus_handle) { listener(view, event, cx) } @@ -59,13 +58,13 @@ pub trait Focusable: Element { fn on_blur( mut self, - listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext) + Send + Sync + 'static, + listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.focus_listeners() - .push(Arc::new(move |view, focus_handle, event, cx| { + .push(Box::new(move |view, focus_handle, event, cx| { if event.blurred.as_ref() == Some(focus_handle) { listener(view, event, cx) } @@ -75,13 +74,13 @@ pub trait Focusable: Element { fn on_focus_in( mut self, - listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext) + Send + Sync + 'static, + listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.focus_listeners() - .push(Arc::new(move |view, focus_handle, event, cx| { + .push(Box::new(move |view, focus_handle, event, cx| { let descendant_blurred = event .blurred .as_ref() @@ -100,13 +99,13 @@ pub trait Focusable: Element { fn on_focus_out( mut self, - listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext) + Send + Sync + 'static, + listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.focus_listeners() - .push(Arc::new(move |view, focus_handle, event, cx| { + .push(Box::new(move |view, focus_handle, event, cx| { let descendant_blurred = event .blurred .as_ref() @@ -123,7 +122,7 @@ pub trait Focusable: Element { } } -pub trait ElementFocus: 'static + Send + Sync { +pub trait ElementFocus: 'static + Send { fn as_focusable(&self) -> Option<&FocusEnabled>; fn as_focusable_mut(&mut self) -> Option<&mut FocusEnabled>; @@ -138,7 +137,7 @@ pub trait ElementFocus: 'static + Send + Sync { .focus_handle .get_or_insert_with(|| focus_handle.unwrap_or_else(|| cx.focus_handle())) .clone(); - for listener in focusable.focus_listeners.iter().cloned() { + for listener in focusable.focus_listeners.drain(..) { let focus_handle = focus_handle.clone(); cx.on_focus_changed(move |view, event, cx| { listener(view, &focus_handle, event, cx) diff --git a/crates/gpui2/src/gpui2.rs b/crates/gpui2/src/gpui2.rs index 9fcc2e4478..163ef93809 100644 --- a/crates/gpui2/src/gpui2.rs +++ b/crates/gpui2/src/gpui2.rs @@ -67,7 +67,7 @@ use std::{ }; use taffy::TaffyLayoutEngine; -type AnyBox = Box; +type AnyBox = Box; pub trait Context { type EntityContext<'a, 'w, T>; @@ -78,7 +78,7 @@ pub trait Context { build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, T>) -> T, ) -> Self::Result> where - T: 'static + Send + Sync; + T: 'static + Send; fn update_entity( &mut self, @@ -119,7 +119,7 @@ impl Context for MainThread { build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, T>) -> T, ) -> Self::Result> where - T: Any + Send + Sync, + T: 'static + Send, { self.0.entity(|cx| { let cx = unsafe { @@ -154,7 +154,7 @@ pub trait BorrowAppContext { where F: FnOnce(&mut Self) -> R; - fn set_global(&mut self, global: T); + fn set_global(&mut self, global: T); } impl BorrowAppContext for C @@ -171,7 +171,7 @@ where result } - fn set_global(&mut self, global: G) { + fn set_global(&mut self, global: G) { self.borrow_mut().set_global(global) } } diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rs index 9ec6c38dfe..ad3eddfa62 100644 --- a/crates/gpui2/src/interactive.rs +++ b/crates/gpui2/src/interactive.rs @@ -12,6 +12,7 @@ use std::{ any::{Any, TypeId}, fmt::Debug, marker::PhantomData, + mem, ops::Deref, path::PathBuf, sync::Arc, @@ -48,14 +49,14 @@ pub trait StatelessInteractive: Element { fn on_mouse_down( mut self, button: MouseButton, - handler: impl Fn(&mut V, &MouseDownEvent, &mut ViewContext) + Send + Sync + 'static, + handler: impl Fn(&mut V, &MouseDownEvent, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.stateless_interaction() .mouse_down_listeners - .push(Arc::new(move |view, event, bounds, phase, cx| { + .push(Box::new(move |view, event, bounds, phase, cx| { if phase == DispatchPhase::Bubble && event.button == button && bounds.contains_point(&event.position) @@ -69,14 +70,14 @@ pub trait StatelessInteractive: Element { fn on_mouse_up( mut self, button: MouseButton, - handler: impl Fn(&mut V, &MouseUpEvent, &mut ViewContext) + Send + Sync + 'static, + handler: impl Fn(&mut V, &MouseUpEvent, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.stateless_interaction() .mouse_up_listeners - .push(Arc::new(move |view, event, bounds, phase, cx| { + .push(Box::new(move |view, event, bounds, phase, cx| { if phase == DispatchPhase::Bubble && event.button == button && bounds.contains_point(&event.position) @@ -90,14 +91,14 @@ pub trait StatelessInteractive: Element { fn on_mouse_down_out( mut self, button: MouseButton, - handler: impl Fn(&mut V, &MouseDownEvent, &mut ViewContext) + Send + Sync + 'static, + handler: impl Fn(&mut V, &MouseDownEvent, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.stateless_interaction() .mouse_down_listeners - .push(Arc::new(move |view, event, bounds, phase, cx| { + .push(Box::new(move |view, event, bounds, phase, cx| { if phase == DispatchPhase::Capture && event.button == button && !bounds.contains_point(&event.position) @@ -111,14 +112,14 @@ pub trait StatelessInteractive: Element { fn on_mouse_up_out( mut self, button: MouseButton, - handler: impl Fn(&mut V, &MouseUpEvent, &mut ViewContext) + Send + Sync + 'static, + handler: impl Fn(&mut V, &MouseUpEvent, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.stateless_interaction() .mouse_up_listeners - .push(Arc::new(move |view, event, bounds, phase, cx| { + .push(Box::new(move |view, event, bounds, phase, cx| { if phase == DispatchPhase::Capture && event.button == button && !bounds.contains_point(&event.position) @@ -131,14 +132,14 @@ pub trait StatelessInteractive: Element { fn on_mouse_move( mut self, - handler: impl Fn(&mut V, &MouseMoveEvent, &mut ViewContext) + Send + Sync + 'static, + handler: impl Fn(&mut V, &MouseMoveEvent, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.stateless_interaction() .mouse_move_listeners - .push(Arc::new(move |view, event, bounds, phase, cx| { + .push(Box::new(move |view, event, bounds, phase, cx| { if phase == DispatchPhase::Bubble && bounds.contains_point(&event.position) { handler(view, event, cx); } @@ -148,14 +149,14 @@ pub trait StatelessInteractive: Element { fn on_scroll_wheel( mut self, - handler: impl Fn(&mut V, &ScrollWheelEvent, &mut ViewContext) + Send + Sync + 'static, + handler: impl Fn(&mut V, &ScrollWheelEvent, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.stateless_interaction() .scroll_wheel_listeners - .push(Arc::new(move |view, event, bounds, phase, cx| { + .push(Box::new(move |view, event, bounds, phase, cx| { if phase == DispatchPhase::Bubble && bounds.contains_point(&event.position) { handler(view, event, cx); } @@ -176,14 +177,14 @@ pub trait StatelessInteractive: Element { fn on_action( mut self, - listener: impl Fn(&mut V, &A, DispatchPhase, &mut ViewContext) + Send + Sync + 'static, + listener: impl Fn(&mut V, &A, DispatchPhase, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.stateless_interaction().key_listeners.push(( TypeId::of::(), - Arc::new(move |view, event, _, phase, cx| { + Box::new(move |view, event, _, phase, cx| { let event = event.downcast_ref().unwrap(); listener(view, event, phase, cx); None @@ -194,17 +195,14 @@ pub trait StatelessInteractive: Element { fn on_key_down( mut self, - listener: impl Fn(&mut V, &KeyDownEvent, DispatchPhase, &mut ViewContext) - + Send - + Sync - + 'static, + listener: impl Fn(&mut V, &KeyDownEvent, DispatchPhase, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.stateless_interaction().key_listeners.push(( TypeId::of::(), - Arc::new(move |view, event, _, phase, cx| { + Box::new(move |view, event, _, phase, cx| { let event = event.downcast_ref().unwrap(); listener(view, event, phase, cx); None @@ -215,17 +213,14 @@ pub trait StatelessInteractive: Element { fn on_key_up( mut self, - listener: impl Fn(&mut V, &KeyUpEvent, DispatchPhase, &mut ViewContext) - + Send - + Sync - + 'static, + listener: impl Fn(&mut V, &KeyUpEvent, DispatchPhase, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.stateless_interaction().key_listeners.push(( TypeId::of::(), - Arc::new(move |view, event, _, phase, cx| { + Box::new(move |view, event, _, phase, cx| { let event = event.downcast_ref().unwrap(); listener(view, event, phase, cx); None @@ -264,14 +259,14 @@ pub trait StatelessInteractive: Element { fn on_drop( mut self, - listener: impl Fn(&mut V, S, &mut ViewContext) + Send + Sync + 'static, + listener: impl Fn(&mut V, S, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.stateless_interaction().drop_listeners.push(( TypeId::of::(), - Arc::new(move |view, drag_state, cx| { + Box::new(move |view, drag_state, cx| { listener(view, *drag_state.downcast().unwrap(), cx); }), )); @@ -307,26 +302,26 @@ pub trait StatefulInteractive: StatelessInteractive { fn on_click( mut self, - listener: impl Fn(&mut V, &ClickEvent, &mut ViewContext) + Send + Sync + 'static, + listener: impl Fn(&mut V, &ClickEvent, &mut ViewContext) + Send + 'static, ) -> Self where Self: Sized, { self.stateful_interaction() .click_listeners - .push(Arc::new(move |view, event, cx| listener(view, event, cx))); + .push(Box::new(move |view, event, cx| listener(view, event, cx))); self } fn on_drag( mut self, - listener: impl Fn(&mut V, &mut ViewContext) -> Drag + Send + Sync + 'static, + listener: impl Fn(&mut V, &mut ViewContext) -> Drag + Send + 'static, ) -> Self where Self: Sized, - S: Any + Send + Sync, + S: Any + Send, R: Fn(&mut V, &mut ViewContext) -> E, - R: 'static + Send + Sync, + R: 'static + Send, E: Component, { debug_assert!( @@ -334,7 +329,7 @@ pub trait StatefulInteractive: StatelessInteractive { "calling on_drag more than once on the same element is not supported" ); self.stateful_interaction().drag_listener = - Some(Arc::new(move |view_state, cursor_offset, cx| { + Some(Box::new(move |view_state, cursor_offset, cx| { let drag = listener(view_state, cx); let view_handle = cx.handle().upgrade().unwrap(); let drag_handle_view = Some( @@ -354,7 +349,7 @@ pub trait StatefulInteractive: StatelessInteractive { } } -pub trait ElementInteraction: 'static + Send + Sync { +pub trait ElementInteraction: 'static + Send { fn as_stateless(&self) -> &StatelessInteraction; fn as_stateless_mut(&mut self) -> &mut StatelessInteraction; fn as_stateful(&self) -> Option<&StatefulInteraction>; @@ -369,7 +364,7 @@ pub trait ElementInteraction: 'static + Send + Sync { cx.with_element_id(stateful.id.clone(), |global_id, cx| { stateful.key_listeners.push(( TypeId::of::(), - Arc::new(move |_, key_down, context, phase, cx| { + Box::new(move |_, key_down, context, phase, cx| { if phase == DispatchPhase::Bubble { let key_down = key_down.downcast_ref::().unwrap(); if let KeyMatch::Some(action) = @@ -387,9 +382,9 @@ pub trait ElementInteraction: 'static + Send + Sync { result }) } else { - let stateless = self.as_stateless(); + let stateless = self.as_stateless_mut(); cx.with_key_dispatch_context(stateless.dispatch_context.clone(), |cx| { - cx.with_key_listeners(&stateless.key_listeners, f) + cx.with_key_listeners(mem::take(&mut stateless.key_listeners), f) }) } } @@ -455,26 +450,26 @@ pub trait ElementInteraction: 'static + Send + Sync { element_state: &mut InteractiveElementState, cx: &mut ViewContext, ) { - let stateless = self.as_stateless(); - for listener in stateless.mouse_down_listeners.iter().cloned() { + let stateless = self.as_stateless_mut(); + for listener in stateless.mouse_down_listeners.drain(..) { cx.on_mouse_event(move |state, event: &MouseDownEvent, phase, cx| { listener(state, event, &bounds, phase, cx); }) } - for listener in stateless.mouse_up_listeners.iter().cloned() { + for listener in stateless.mouse_up_listeners.drain(..) { cx.on_mouse_event(move |state, event: &MouseUpEvent, phase, cx| { listener(state, event, &bounds, phase, cx); }) } - for listener in stateless.mouse_move_listeners.iter().cloned() { + for listener in stateless.mouse_move_listeners.drain(..) { cx.on_mouse_event(move |state, event: &MouseMoveEvent, phase, cx| { listener(state, event, &bounds, phase, cx); }) } - for listener in stateless.scroll_wheel_listeners.iter().cloned() { + for listener in stateless.scroll_wheel_listeners.drain(..) { cx.on_mouse_event(move |state, event: &ScrollWheelEvent, phase, cx| { listener(state, event, &bounds, phase, cx); }) @@ -510,7 +505,7 @@ pub trait ElementInteraction: 'static + Send + Sync { } if cx.active_drag.is_some() { - let drop_listeners = stateless.drop_listeners.clone(); + let drop_listeners = mem::take(&mut stateless.drop_listeners); cx.on_mouse_event(move |view, event: &MouseUpEvent, phase, cx| { if phase == DispatchPhase::Bubble && bounds.contains_point(&event.position) { if let Some(drag_state_type) = @@ -532,9 +527,9 @@ pub trait ElementInteraction: 'static + Send + Sync { }); } - if let Some(stateful) = self.as_stateful() { - let click_listeners = stateful.click_listeners.clone(); - let drag_listener = stateful.drag_listener.clone(); + if let Some(stateful) = self.as_stateful_mut() { + let click_listeners = mem::take(&mut stateful.click_listeners); + let drag_listener = mem::take(&mut stateful.drag_listener); if !click_listeners.is_empty() || drag_listener.is_some() { let pending_mouse_down = element_state.pending_mouse_down.clone(); @@ -690,7 +685,7 @@ impl From for StatefulInteraction { } } -type DropListener = dyn Fn(&mut V, AnyBox, &mut ViewContext) + 'static + Send + Sync; +type DropListener = dyn Fn(&mut V, AnyBox, &mut ViewContext) + 'static + Send; pub struct StatelessInteraction { pub dispatch_context: DispatchContext, @@ -703,7 +698,7 @@ pub struct StatelessInteraction { pub group_hover_style: Option, drag_over_styles: SmallVec<[(TypeId, StyleRefinement); 2]>, group_drag_over_styles: SmallVec<[(TypeId, GroupStyle); 2]>, - drop_listeners: SmallVec<[(TypeId, Arc>); 2]>, + drop_listeners: SmallVec<[(TypeId, Box>); 2]>, } impl StatelessInteraction { @@ -1082,40 +1077,35 @@ pub struct FocusEvent { pub focused: Option, } -pub type MouseDownListener = Arc< +pub type MouseDownListener = Box< dyn Fn(&mut V, &MouseDownEvent, &Bounds, DispatchPhase, &mut ViewContext) + Send - + Sync + 'static, >; -pub type MouseUpListener = Arc< +pub type MouseUpListener = Box< dyn Fn(&mut V, &MouseUpEvent, &Bounds, DispatchPhase, &mut ViewContext) + Send - + Sync + 'static, >; -pub type MouseMoveListener = Arc< +pub type MouseMoveListener = Box< dyn Fn(&mut V, &MouseMoveEvent, &Bounds, DispatchPhase, &mut ViewContext) + Send - + Sync + 'static, >; -pub type ScrollWheelListener = Arc< +pub type ScrollWheelListener = Box< dyn Fn(&mut V, &ScrollWheelEvent, &Bounds, DispatchPhase, &mut ViewContext) + Send - + Sync + 'static, >; -pub type ClickListener = - Arc) + Send + Sync + 'static>; +pub type ClickListener = Box) + Send + 'static>; pub(crate) type DragListener = - Arc, &mut ViewContext) -> AnyDrag + Send + Sync + 'static>; + Box, &mut ViewContext) -> AnyDrag + Send + 'static>; -pub type KeyListener = Arc< +pub type KeyListener = Box< dyn Fn( &mut V, &dyn Any, @@ -1124,6 +1114,5 @@ pub type KeyListener = Arc< &mut ViewContext, ) -> Option> + Send - + Sync + 'static, >; diff --git a/crates/gpui2/src/keymap/matcher.rs b/crates/gpui2/src/keymap/matcher.rs index 494285aaea..c2033a9595 100644 --- a/crates/gpui2/src/keymap/matcher.rs +++ b/crates/gpui2/src/keymap/matcher.rs @@ -1,17 +1,17 @@ use crate::{Action, DispatchContext, Keymap, KeymapVersion, Keystroke}; -use parking_lot::RwLock; +use parking_lot::Mutex; use smallvec::SmallVec; use std::sync::Arc; pub struct KeyMatcher { pending_keystrokes: Vec, - keymap: Arc>, + keymap: Arc>, keymap_version: KeymapVersion, } impl KeyMatcher { - pub fn new(keymap: Arc>) -> Self { - let keymap_version = keymap.read().version(); + pub fn new(keymap: Arc>) -> Self { + let keymap_version = keymap.lock().version(); Self { pending_keystrokes: Vec::new(), keymap_version, @@ -21,7 +21,7 @@ impl KeyMatcher { // todo!("replace with a function that calls an FnMut for every binding matching the action") // pub fn bindings_for_action(&self, action_id: TypeId) -> impl Iterator { - // self.keymap.read().bindings_for_action(action_id) + // self.keymap.lock().bindings_for_action(action_id) // } pub fn clear_pending(&mut self) { @@ -46,7 +46,7 @@ impl KeyMatcher { keystroke: &Keystroke, context_stack: &[&DispatchContext], ) -> KeyMatch { - let keymap = self.keymap.read(); + let keymap = self.keymap.lock(); // Clear pending keystrokes if the keymap has changed since the last matched keystroke. if keymap.version() != self.keymap_version { self.keymap_version = keymap.version(); @@ -89,7 +89,7 @@ impl KeyMatcher { contexts: &[&DispatchContext], ) -> Option> { self.keymap - .read() + .lock() .bindings() .iter() .rev() diff --git a/crates/gpui2/src/subscription.rs b/crates/gpui2/src/subscription.rs index b835311c12..3bf28792bb 100644 --- a/crates/gpui2/src/subscription.rs +++ b/crates/gpui2/src/subscription.rs @@ -21,8 +21,8 @@ struct SubscriberSetState { impl SubscriberSet where - EmitterKey: 'static + Send + Sync + Ord + Clone + Debug, - Callback: 'static + Send + Sync, + EmitterKey: 'static + Send + Ord + Clone + Debug, + Callback: 'static + Send, { pub fn new() -> Self { Self(Arc::new(Mutex::new(SubscriberSetState { @@ -96,7 +96,7 @@ where #[must_use] pub struct Subscription { - unsubscribe: Option>, + unsubscribe: Option>, } impl Subscription { diff --git a/crates/gpui2/src/taffy.rs b/crates/gpui2/src/taffy.rs index ca8b43aa70..1a28ef0568 100644 --- a/crates/gpui2/src/taffy.rs +++ b/crates/gpui2/src/taffy.rs @@ -53,10 +53,7 @@ impl TaffyLayoutEngine { &mut self, style: Style, rem_size: Pixels, - measure: impl Fn(Size>, Size) -> Size - + Send - + Sync - + 'static, + measure: impl Fn(Size>, Size) -> Size + Send + Sync + 'static, ) -> LayoutId { let style = style.to_taffy(rem_size); @@ -179,7 +176,7 @@ struct Measureable(F); impl taffy::tree::Measurable for Measureable where - F: Send + Sync + Fn(Size>, Size) -> Size, + F: Fn(Size>, Size) -> Size + Send + Sync, { fn measure( &self, diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rs index a27faed07d..d2fe143faa 100644 --- a/crates/gpui2/src/view.rs +++ b/crates/gpui2/src/view.rs @@ -8,14 +8,12 @@ use std::{marker::PhantomData, sync::Arc}; pub struct View { state: Handle, - render: Arc) -> AnyElement + Send + Sync + 'static>, + render: Arc) -> AnyElement + Send + 'static>>, } impl View { pub fn into_any(self) -> AnyView { - AnyView { - view: Arc::new(Mutex::new(self)), - } + AnyView(Arc::new(self)) } } @@ -30,14 +28,16 @@ impl Clone for View { pub fn view( state: Handle, - render: impl Fn(&mut V, &mut ViewContext) -> E + Send + Sync + 'static, + render: impl Fn(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + 'static, ) -> View where E: Component, { View { state, - render: Arc::new(move |state, cx| render(state, cx).render()), + render: Arc::new(Mutex::new( + move |state: &mut V, cx: &mut ViewContext<'_, '_, V>| render(state, cx).render(), + )), } } @@ -64,7 +64,7 @@ impl Element<()> for View { cx: &mut ViewContext<()>, ) -> Self::ElementState { self.state.update(cx, |state, cx| { - let mut any_element = (self.render)(state, cx); + let mut any_element = (self.render.lock())(state, cx); any_element.initialize(state, cx); any_element }) @@ -96,7 +96,6 @@ struct EraseViewState { } unsafe impl Send for EraseViewState {} -unsafe impl Sync for EraseViewState {} impl Component for EraseViewState { fn render(self) -> AnyElement { @@ -142,9 +141,9 @@ impl Element for EraseViewState EntityId; - fn initialize(&mut self, cx: &mut WindowContext) -> AnyBox; - fn layout(&mut self, element: &mut AnyBox, cx: &mut WindowContext) -> LayoutId; - fn paint(&mut self, bounds: Bounds, element: &mut AnyBox, cx: &mut WindowContext); + fn initialize(&self, cx: &mut WindowContext) -> AnyBox; + fn layout(&self, element: &mut AnyBox, cx: &mut WindowContext) -> LayoutId; + fn paint(&self, bounds: Bounds, element: &mut AnyBox, cx: &mut WindowContext); } impl ViewObject for View { @@ -152,17 +151,17 @@ impl ViewObject for View { self.state.entity_id } - fn initialize(&mut self, cx: &mut WindowContext) -> AnyBox { + fn initialize(&self, cx: &mut WindowContext) -> AnyBox { cx.with_element_id(self.entity_id(), |_global_id, cx| { self.state.update(cx, |state, cx| { - let mut any_element = Box::new((self.render)(state, cx)); + let mut any_element = Box::new((self.render.lock())(state, cx)); any_element.initialize(state, cx); any_element as AnyBox }) }) } - fn layout(&mut self, element: &mut AnyBox, cx: &mut WindowContext) -> LayoutId { + fn layout(&self, element: &mut AnyBox, cx: &mut WindowContext) -> LayoutId { cx.with_element_id(self.entity_id(), |_global_id, cx| { self.state.update(cx, |state, cx| { let element = element.downcast_mut::>().unwrap(); @@ -171,7 +170,7 @@ impl ViewObject for View { }) } - fn paint(&mut self, _: Bounds, element: &mut AnyBox, cx: &mut WindowContext) { + fn paint(&self, _: Bounds, element: &mut AnyBox, cx: &mut WindowContext) { cx.with_element_id(self.entity_id(), |_global_id, cx| { self.state.update(cx, |state, cx| { let element = element.downcast_mut::>().unwrap(); @@ -181,9 +180,8 @@ impl ViewObject for View { } } -pub struct AnyView { - view: Arc>, -} +#[derive(Clone)] +pub struct AnyView(Arc); impl Component for AnyView { fn render(self) -> AnyElement { @@ -198,7 +196,7 @@ impl Element<()> for AnyView { type ElementState = AnyBox; fn id(&self) -> Option { - Some(ElementId::View(self.view.lock().entity_id())) + Some(ElementId::View(self.0.entity_id())) } fn initialize( @@ -207,7 +205,7 @@ impl Element<()> for AnyView { _: Option, cx: &mut ViewContext<()>, ) -> Self::ElementState { - self.view.lock().initialize(cx) + self.0.initialize(cx) } fn layout( @@ -216,7 +214,7 @@ impl Element<()> for AnyView { element: &mut Self::ElementState, cx: &mut ViewContext<()>, ) -> LayoutId { - self.view.lock().layout(element, cx) + self.0.layout(element, cx) } fn paint( @@ -226,7 +224,7 @@ impl Element<()> for AnyView { element: &mut AnyBox, cx: &mut ViewContext<()>, ) { - self.view.lock().paint(bounds, element, cx) + self.0.paint(bounds, element, cx) } } @@ -236,7 +234,6 @@ struct EraseAnyViewState { } unsafe impl Send for EraseAnyViewState {} -unsafe impl Sync for EraseAnyViewState {} impl Component for EraseAnyViewState { fn render(self) -> AnyElement { @@ -257,7 +254,7 @@ impl Element for EraseAnyViewState { _: Option, cx: &mut ViewContext, ) -> Self::ElementState { - self.view.view.lock().initialize(cx) + self.view.0.initialize(cx) } fn layout( @@ -266,7 +263,7 @@ impl Element for EraseAnyViewState { element: &mut Self::ElementState, cx: &mut ViewContext, ) -> LayoutId { - self.view.view.lock().layout(element, cx) + self.view.0.layout(element, cx) } fn paint( @@ -276,14 +273,6 @@ impl Element for EraseAnyViewState { element: &mut Self::ElementState, cx: &mut ViewContext, ) { - self.view.view.lock().paint(bounds, element, cx) - } -} - -impl Clone for AnyView { - fn clone(&self) -> Self { - Self { - view: self.view.clone(), - } + self.view.0.paint(bounds, element, cx) } } diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index fc9b8b8de8..4a203014db 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -46,8 +46,8 @@ pub enum DispatchPhase { Capture, } -type AnyListener = Arc; -type AnyKeyListener = Arc< +type AnyListener = Box; +type AnyKeyListener = Box< dyn Fn( &dyn Any, &[&DispatchContext], @@ -55,10 +55,9 @@ type AnyKeyListener = Arc< &mut WindowContext, ) -> Option> + Send - + Sync + 'static, >; -type AnyFocusListener = Arc; +type AnyFocusListener = Box; slotmap::new_key_type! { pub struct FocusId; } @@ -500,7 +499,7 @@ impl<'a, 'w> WindowContext<'a, 'w> { pub fn on_mouse_event( &mut self, - handler: impl Fn(&Event, DispatchPhase, &mut WindowContext) + Send + Sync + 'static, + handler: impl Fn(&Event, DispatchPhase, &mut WindowContext) + Send + 'static, ) { let order = self.window.z_index_stack.clone(); self.window @@ -509,7 +508,7 @@ impl<'a, 'w> WindowContext<'a, 'w> { .or_default() .push(( order, - Arc::new(move |event: &dyn Any, phase, cx| { + Box::new(move |event: &dyn Any, phase, cx| { handler(event.downcast_ref().unwrap(), phase, cx) }), )) @@ -1081,7 +1080,7 @@ impl<'a, 'w> WindowContext<'a, 'w> { pub fn observe_global( &mut self, - f: impl Fn(&mut WindowContext<'_, '_>) + Send + Sync + 'static, + f: impl Fn(&mut WindowContext<'_, '_>) + Send + 'static, ) -> Subscription { let window_id = self.window.handle.id; self.global_observers.insert( @@ -1178,7 +1177,7 @@ impl Context for WindowContext<'_, '_> { build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, T>) -> T, ) -> Handle where - T: Any + Send + Sync, + T: 'static + Send, { let slot = self.app.entities.reserve(); let entity = build_entity(&mut ViewContext::mutable( @@ -1311,7 +1310,7 @@ pub trait BorrowWindow: BorrowMut + BorrowMut { f: impl FnOnce(Option, &mut Self) -> (R, S), ) -> R where - S: Any + Send + Sync, + S: 'static + Send, { self.with_element_id(id, |global_id, cx| { if let Some(any) = cx @@ -1347,7 +1346,7 @@ pub trait BorrowWindow: BorrowMut + BorrowMut { f: impl FnOnce(Option, &mut Self) -> (R, S), ) -> R where - S: Any + Send + Sync, + S: 'static + Send, { if let Some(element_id) = element_id { self.with_element_state(element_id, f) @@ -1438,7 +1437,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> { pub fn on_next_frame(&mut self, f: impl FnOnce(&mut V, &mut ViewContext) + Send + 'static) where - V: Any + Send + Sync, + V: Any + Send, { let entity = self.handle(); self.window_cx.on_next_frame(move |cx| { @@ -1449,14 +1448,11 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> { pub fn observe( &mut self, handle: &Handle, - mut on_notify: impl FnMut(&mut V, Handle, &mut ViewContext<'_, '_, V>) - + Send - + Sync - + 'static, + mut on_notify: impl FnMut(&mut V, Handle, &mut ViewContext<'_, '_, V>) + Send + 'static, ) -> Subscription where E: 'static, - V: Any + Send + Sync, + V: Any + Send, { let this = self.handle(); let handle = handle.downgrade(); @@ -1482,7 +1478,6 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> { handle: &Handle, mut on_event: impl FnMut(&mut V, Handle, &E::Event, &mut ViewContext<'_, '_, V>) + Send - + Sync + 'static, ) -> Subscription { let this = self.handle(); @@ -1507,7 +1502,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> { pub fn on_release( &mut self, - mut on_release: impl FnMut(&mut V, &mut WindowContext) + Send + Sync + 'static, + mut on_release: impl FnMut(&mut V, &mut WindowContext) + Send + 'static, ) -> Subscription { let window_handle = self.window.handle; self.app.release_listeners.insert( @@ -1523,10 +1518,10 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> { pub fn observe_release( &mut self, handle: &Handle, - mut on_release: impl FnMut(&mut V, &mut T, &mut ViewContext<'_, '_, V>) + Send + Sync + 'static, + mut on_release: impl FnMut(&mut V, &mut T, &mut ViewContext<'_, '_, V>) + Send + 'static, ) -> Subscription where - V: Any + Send + Sync, + V: Any + Send, { let this = self.handle(); let window_handle = self.window.handle; @@ -1551,10 +1546,10 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> { pub fn on_focus_changed( &mut self, - listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext) + Send + Sync + 'static, + listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext) + Send + 'static, ) { let handle = self.handle(); - self.window.focus_listeners.push(Arc::new(move |event, cx| { + self.window.focus_listeners.push(Box::new(move |event, cx| { handle .update(cx, |view, cx| listener(view, event, cx)) .log_err(); @@ -1563,13 +1558,14 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> { pub fn with_key_listeners( &mut self, - key_listeners: &[(TypeId, KeyListener)], + key_listeners: impl IntoIterator)>, f: impl FnOnce(&mut Self) -> R, ) -> R { + let old_stack_len = self.window.key_dispatch_stack.len(); if !self.window.freeze_key_dispatch_stack { - for (event_type, listener) in key_listeners.iter().cloned() { + for (event_type, listener) in key_listeners { let handle = self.handle(); - let listener = Arc::new( + let listener = Box::new( move |event: &dyn Any, context_stack: &[&DispatchContext], phase: DispatchPhase, @@ -1594,8 +1590,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> { let result = f(self); if !self.window.freeze_key_dispatch_stack { - let prev_len = self.window.key_dispatch_stack.len() - key_listeners.len(); - self.window.key_dispatch_stack.truncate(prev_len); + self.window.key_dispatch_stack.truncate(old_stack_len); } result @@ -1681,7 +1676,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> { pub fn update_global(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R where - G: 'static + Send + Sync, + G: 'static + Send, { let mut global = self.app.lease_global::(); let result = f(&mut global, self); @@ -1691,7 +1686,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> { pub fn observe_global( &mut self, - f: impl Fn(&mut V, &mut ViewContext<'_, '_, V>) + Send + Sync + 'static, + f: impl Fn(&mut V, &mut ViewContext<'_, '_, V>) + Send + 'static, ) -> Subscription { let window_id = self.window.handle.id; let handle = self.handle(); @@ -1708,7 +1703,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> { pub fn on_mouse_event( &mut self, - handler: impl Fn(&mut V, &Event, DispatchPhase, &mut ViewContext) + Send + Sync + 'static, + handler: impl Fn(&mut V, &Event, DispatchPhase, &mut ViewContext) + Send + 'static, ) { let handle = self.handle().upgrade().unwrap(); self.window_cx.on_mouse_event(move |event, phase, cx| { @@ -1722,7 +1717,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> { impl<'a, 'w, V> ViewContext<'a, 'w, V> where V: EventEmitter, - V::Event: Any + Send + Sync, + V::Event: Any + Send, { pub fn emit(&mut self, event: V::Event) { let emitter = self.view_state.entity_id; @@ -1742,7 +1737,7 @@ impl<'a, 'w, V> Context for ViewContext<'a, 'w, V> { build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, T>) -> T, ) -> Handle where - T: 'static + Send + Sync, + T: 'static + Send, { self.window_cx.entity(build_entity) } diff --git a/crates/live_kit_client/examples/test_app.rs b/crates/live_kit_client/examples/test_app.rs index f2169d7f30..fa5bb1bc40 100644 --- a/crates/live_kit_client/examples/test_app.rs +++ b/crates/live_kit_client/examples/test_app.rs @@ -61,7 +61,7 @@ fn main() { let mut audio_track_updates = room_b.remote_audio_track_updates(); let audio_track = LocalAudioTrack::create(); - let audio_track_publication = room_a.publish_audio_track(&audio_track).await.unwrap(); + let audio_track_publication = room_a.publish_audio_track(audio_track).await.unwrap(); if let RemoteAudioTrackUpdate::Subscribed(track, _) = audio_track_updates.next().await.unwrap() @@ -132,10 +132,8 @@ fn main() { let display = displays.into_iter().next().unwrap(); let local_video_track = LocalVideoTrack::screen_share_for_display(&display); - let local_video_track_publication = room_a - .publish_video_track(&local_video_track) - .await - .unwrap(); + let local_video_track_publication = + room_a.publish_video_track(local_video_track).await.unwrap(); if let RemoteVideoTrackUpdate::Subscribed(track) = video_track_updates.next().await.unwrap() diff --git a/crates/live_kit_client/src/prod.rs b/crates/live_kit_client/src/prod.rs index ab54174430..007c47ac63 100644 --- a/crates/live_kit_client/src/prod.rs +++ b/crates/live_kit_client/src/prod.rs @@ -229,7 +229,7 @@ impl Room { pub fn publish_video_track( self: &Arc, - track: &LocalVideoTrack, + track: LocalVideoTrack, ) -> impl Future> { let (tx, rx) = oneshot::channel::>(); extern "C" fn callback(tx: *mut c_void, publication: *mut c_void, error: CFStringRef) { @@ -255,7 +255,7 @@ impl Room { pub fn publish_audio_track( self: &Arc, - track: &LocalAudioTrack, + track: LocalAudioTrack, ) -> impl Future> { let (tx, rx) = oneshot::channel::>(); extern "C" fn callback(tx: *mut c_void, publication: *mut c_void, error: CFStringRef) { @@ -622,8 +622,6 @@ impl Drop for RoomDelegate { pub struct LocalAudioTrack(*const c_void); unsafe impl Send for LocalAudioTrack {} -// todo!(Sync is not ok here. We need to remove it) -unsafe impl Sync for LocalAudioTrack {} impl LocalAudioTrack { pub fn create() -> Self { @@ -639,8 +637,6 @@ impl Drop for LocalAudioTrack { pub struct LocalVideoTrack(*const c_void); unsafe impl Send for LocalVideoTrack {} -// todo!(Sync is not ok here. We need to remove it) -unsafe impl Sync for LocalVideoTrack {} impl LocalVideoTrack { pub fn screen_share_for_display(display: &MacOSDisplay) -> Self { @@ -656,8 +652,6 @@ impl Drop for LocalVideoTrack { pub struct LocalTrackPublication(*const c_void); unsafe impl Send for LocalTrackPublication {} -// todo!(Sync is not ok here. We need to remove it) -unsafe impl Sync for LocalTrackPublication {} impl LocalTrackPublication { pub fn new(native_track_publication: *const c_void) -> Self { @@ -702,8 +696,6 @@ impl Drop for LocalTrackPublication { pub struct RemoteTrackPublication(*const c_void); unsafe impl Send for RemoteTrackPublication {} -// todo!(Sync is not ok here. We need to remove it) -unsafe impl Sync for RemoteTrackPublication {} impl RemoteTrackPublication { pub fn new(native_track_publication: *const c_void) -> Self { @@ -761,8 +753,6 @@ pub struct RemoteAudioTrack { } unsafe impl Send for RemoteAudioTrack {} -// todo!(Sync is not ok here. We need to remove it) -unsafe impl Sync for RemoteAudioTrack {} impl RemoteAudioTrack { fn new(native_track: *const c_void, sid: Sid, publisher_id: String) -> Self { @@ -801,8 +791,6 @@ pub struct RemoteVideoTrack { } unsafe impl Send for RemoteVideoTrack {} -// todo!(Sync is not ok here. We need to remove it) -unsafe impl Sync for RemoteVideoTrack {} impl RemoteVideoTrack { fn new(native_track: *const c_void, sid: Sid, publisher_id: String) -> Self { @@ -886,8 +874,6 @@ pub enum RemoteAudioTrackUpdate { pub struct MacOSDisplay(*const c_void); unsafe impl Send for MacOSDisplay {} -// todo!(Sync is not ok here. We need to remove it) -unsafe impl Sync for MacOSDisplay {} impl MacOSDisplay { fn new(ptr: *const c_void) -> Self { diff --git a/crates/live_kit_client/src/test.rs b/crates/live_kit_client/src/test.rs index 8df8ab4abb..643322fdbb 100644 --- a/crates/live_kit_client/src/test.rs +++ b/crates/live_kit_client/src/test.rs @@ -371,7 +371,7 @@ impl Room { pub fn publish_video_track( self: &Arc, - track: &LocalVideoTrack, + track: LocalVideoTrack, ) -> impl Future> { let this = self.clone(); let track = track.clone(); @@ -384,7 +384,7 @@ impl Room { } pub fn publish_audio_track( self: &Arc, - track: &LocalAudioTrack, + track: LocalAudioTrack, ) -> impl Future> { let this = self.clone(); let track = track.clone(); diff --git a/crates/ui2/src/theme.rs b/crates/ui2/src/theme.rs index d8d924dbb0..e5075c912f 100644 --- a/crates/ui2/src/theme.rs +++ b/crates/ui2/src/theme.rs @@ -152,8 +152,8 @@ pub struct Themed { impl Component for Themed where V: 'static, - E: 'static + Element + Send + Sync, - E::ElementState: Send + Sync, + E: 'static + Element + Send, + E::ElementState: Send, { fn render(self) -> AnyElement { AnyElement::new(self) @@ -163,10 +163,10 @@ where #[derive(Default)] struct ThemeStack(Vec); -impl + Send + Sync> Element for Themed +impl + Send> Element for Themed where V: 'static, - E::ElementState: Send + Sync, + E::ElementState: Send, { type ElementState = E::ElementState;