Reduce the need for Send + Sync bounds on generics

This commit is contained in:
Nathan Sobo
2023-10-24 14:20:01 +02:00
parent 4d621f355d
commit 0910760b76
17 changed files with 405 additions and 362 deletions
+7 -22
View File
@@ -9,7 +9,7 @@ use refineable::Refineable;
use smallvec::SmallVec;
pub struct Div<
V: 'static + Send + Sync,
V: 'static,
I: ElementInteraction<V> = StatelessInteraction<V>,
F: ElementFocus<V> = FocusDisabled,
> {
@@ -20,10 +20,7 @@ pub struct Div<
base_style: StyleRefinement,
}
pub fn div<V>() -> Div<V, StatelessInteraction<V>, FocusDisabled>
where
V: 'static + Send + Sync,
{
pub fn div<V: 'static>() -> Div<V, StatelessInteraction<V>, FocusDisabled> {
Div {
interaction: StatelessInteraction::default(),
focus: FocusDisabled,
@@ -35,8 +32,8 @@ where
impl<V, F> Div<V, StatelessInteraction<V>, F>
where
V: 'static,
F: ElementFocus<V>,
V: 'static + Send + Sync,
{
pub fn id(self, id: impl Into<ElementId>) -> Div<V, StatefulInteraction<V>, F> {
Div {
@@ -53,7 +50,6 @@ impl<V, I, F> Div<V, I, F>
where
I: ElementInteraction<V>,
F: ElementFocus<V>,
V: 'static + Send + Sync,
{
pub fn group(mut self, group: impl Into<SharedString>) -> Self {
self.group = Some(group.into());
@@ -108,10 +104,7 @@ where
}
}
impl<V> Div<V, StatefulInteraction<V>, FocusDisabled>
where
V: 'static + Send + Sync,
{
impl<V: 'static> Div<V, StatefulInteraction<V>, FocusDisabled> {
pub fn focusable(self) -> Div<V, StatefulInteraction<V>, FocusEnabled<V>> {
Div {
interaction: self.interaction,
@@ -152,10 +145,7 @@ where
}
}
impl<V> Div<V, StatelessInteraction<V>, FocusDisabled>
where
V: 'static + Send + Sync,
{
impl<V: 'static> Div<V, StatelessInteraction<V>, FocusDisabled> {
pub fn track_focus(
self,
handle: &FocusHandle,
@@ -172,8 +162,8 @@ where
impl<V, I> Focusable for Div<V, I, FocusEnabled<V>>
where
V: 'static,
I: ElementInteraction<V>,
V: 'static + Send + Sync,
{
fn focus_listeners(&mut self) -> &mut FocusListeners<V> {
&mut self.focus.focus_listeners
@@ -203,7 +193,6 @@ impl<V, I, F> Element for Div<V, I, F>
where
I: ElementInteraction<V>,
F: ElementFocus<V>,
V: 'static + Send + Sync,
{
type ViewState = V;
type ElementState = DivState;
@@ -317,9 +306,9 @@ where
impl<V, I, F> IntoAnyElement<V> for Div<V, I, F>
where
// V: Any + Send + Sync,
I: ElementInteraction<V>,
F: ElementFocus<V>,
V: 'static + Send + Sync,
{
fn into_any(self) -> AnyElement<V> {
AnyElement::new(self)
@@ -330,7 +319,6 @@ impl<V, I, F> ParentElement for Div<V, I, F>
where
I: ElementInteraction<V>,
F: ElementFocus<V>,
V: 'static + Send + Sync,
{
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<Self::ViewState>; 2]> {
&mut self.children
@@ -341,7 +329,6 @@ impl<V, I, F> Styled for Div<V, I, F>
where
I: ElementInteraction<V>,
F: ElementFocus<V>,
V: 'static + Send + Sync,
{
fn style(&mut self) -> &mut StyleRefinement {
&mut self.base_style
@@ -352,7 +339,6 @@ impl<V, I, F> StatelessInteractive for Div<V, I, F>
where
I: ElementInteraction<V>,
F: ElementFocus<V>,
V: 'static + Send + Sync,
{
fn stateless_interaction(&mut self) -> &mut StatelessInteraction<V> {
self.interaction.as_stateless_mut()
@@ -362,7 +348,6 @@ where
impl<V, F> StatefulInteractive for Div<V, StatefulInteraction<V>, F>
where
F: ElementFocus<V>,
V: 'static + Send + Sync,
{
fn stateful_interaction(&mut self) -> &mut StatefulInteraction<Self::ViewState> {
&mut self.interaction
+4 -13
View File
@@ -8,7 +8,7 @@ use futures::FutureExt;
use util::ResultExt;
pub struct Img<
V: 'static + Send + Sync,
V: 'static,
I: ElementInteraction<V> = StatelessInteraction<V>,
F: ElementFocus<V> = FocusDisabled,
> {
@@ -17,10 +17,7 @@ pub struct Img<
grayscale: bool,
}
pub fn img<V>() -> Img<V, StatelessInteraction<V>, FocusDisabled>
where
V: 'static + Send + Sync,
{
pub fn img<V: 'static>() -> Img<V, StatelessInteraction<V>, FocusDisabled> {
Img {
base: div(),
uri: None,
@@ -30,7 +27,7 @@ where
impl<V, I, F> Img<V, I, F>
where
V: 'static + Send + Sync,
V: 'static,
I: ElementInteraction<V>,
F: ElementFocus<V>,
{
@@ -47,7 +44,6 @@ where
impl<V, F> Img<V, StatelessInteraction<V>, F>
where
V: 'static + Send + Sync,
F: ElementFocus<V>,
{
pub fn id(self, id: impl Into<ElementId>) -> Img<V, StatefulInteraction<V>, F> {
@@ -61,7 +57,6 @@ where
impl<V, I, F> IntoAnyElement<V> for Img<V, I, F>
where
V: 'static + Send + Sync,
I: ElementInteraction<V>,
F: ElementFocus<V>,
{
@@ -72,7 +67,6 @@ where
impl<V, I, F> Element for Img<V, I, F>
where
V: Send + Sync + 'static,
I: ElementInteraction<V>,
F: ElementFocus<V>,
{
@@ -141,7 +135,6 @@ where
impl<V, I, F> Styled for Img<V, I, F>
where
V: 'static + Send + Sync,
I: ElementInteraction<V>,
F: ElementFocus<V>,
{
@@ -152,7 +145,6 @@ where
impl<V, I, F> StatelessInteractive for Img<V, I, F>
where
V: 'static + Send + Sync,
I: ElementInteraction<V>,
F: ElementFocus<V>,
{
@@ -163,7 +155,6 @@ where
impl<V, F> StatefulInteractive for Img<V, StatefulInteraction<V>, F>
where
V: 'static + Send + Sync,
F: ElementFocus<V>,
{
fn stateful_interaction(&mut self) -> &mut StatefulInteraction<Self::ViewState> {
@@ -173,7 +164,7 @@ where
impl<V, I> Focusable for Img<V, I, FocusEnabled<V>>
where
V: 'static + Send + Sync,
V: 'static,
I: ElementInteraction<V>,
{
fn focus_listeners(&mut self) -> &mut FocusListeners<Self::ViewState> {
+4 -14
View File
@@ -7,7 +7,7 @@ use crate::{
use util::ResultExt;
pub struct Svg<
V: 'static + Send + Sync,
V: 'static,
I: ElementInteraction<V> = StatelessInteraction<V>,
F: ElementFocus<V> = FocusDisabled,
> {
@@ -15,10 +15,7 @@ pub struct Svg<
path: Option<SharedString>,
}
pub fn svg<V>() -> Svg<V, StatelessInteraction<V>, FocusDisabled>
where
V: 'static + Send + Sync,
{
pub fn svg<V: 'static>() -> Svg<V, StatelessInteraction<V>, FocusDisabled> {
Svg {
base: div(),
path: None,
@@ -27,7 +24,6 @@ where
impl<V, I, F> Svg<V, I, F>
where
V: 'static + Send + Sync,
I: ElementInteraction<V>,
F: ElementFocus<V>,
{
@@ -39,7 +35,6 @@ where
impl<V, F> Svg<V, StatelessInteraction<V>, F>
where
V: 'static + Send + Sync,
F: ElementFocus<V>,
{
pub fn id(self, id: impl Into<ElementId>) -> Svg<V, StatefulInteraction<V>, F> {
@@ -52,7 +47,6 @@ where
impl<V, I, F> IntoAnyElement<V> for Svg<V, I, F>
where
V: 'static + Send + Sync,
I: ElementInteraction<V>,
F: ElementFocus<V>,
{
@@ -63,7 +57,6 @@ where
impl<V, I, F> Element for Svg<V, I, F>
where
V: 'static + Send + Sync,
I: ElementInteraction<V>,
F: ElementFocus<V>,
{
@@ -115,7 +108,6 @@ where
impl<V, I, F> Styled for Svg<V, I, F>
where
V: 'static + Send + Sync,
I: ElementInteraction<V>,
F: ElementFocus<V>,
{
@@ -126,7 +118,6 @@ where
impl<V, I, F> StatelessInteractive for Svg<V, I, F>
where
V: 'static + Send + Sync,
I: ElementInteraction<V>,
F: ElementFocus<V>,
{
@@ -137,7 +128,7 @@ where
impl<V, F> StatefulInteractive for Svg<V, StatefulInteraction<V>, F>
where
V: 'static + Send + Sync,
V: 'static,
F: ElementFocus<V>,
{
fn stateful_interaction(&mut self) -> &mut StatefulInteraction<Self::ViewState> {
@@ -145,9 +136,8 @@ where
}
}
impl<V, I> Focusable for Svg<V, I, FocusEnabled<V>>
impl<V: 'static, I> Focusable for Svg<V, I, FocusEnabled<V>>
where
V: 'static + Send + Sync,
I: ElementInteraction<V>,
{
fn focus_listeners(&mut self) -> &mut FocusListeners<Self::ViewState> {
+10 -7
View File
@@ -7,8 +7,8 @@ use smallvec::SmallVec;
use std::{marker::PhantomData, sync::Arc};
use util::ResultExt;
impl<S: 'static + Send + Sync> IntoAnyElement<S> for SharedString {
fn into_any(self) -> AnyElement<S> {
impl<V: 'static> IntoAnyElement<V> for SharedString {
fn into_any(self) -> AnyElement<V> {
Text {
text: self,
state_type: PhantomData,
@@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> IntoAnyElement<S> for SharedString {
}
}
impl<V: 'static + Send + Sync> IntoAnyElement<V> for &'static str {
impl<V: 'static> IntoAnyElement<V> for &'static str {
fn into_any(self) -> AnyElement<V> {
Text {
text: self.into(),
@@ -29,8 +29,8 @@ impl<V: 'static + Send + Sync> IntoAnyElement<V> for &'static str {
// TODO: Figure out how to pass `String` to `child` without this.
// This impl doesn't exist in the `gpui2` crate.
impl<S: 'static + Send + Sync> IntoAnyElement<S> for String {
fn into_any(self) -> AnyElement<S> {
impl<V: 'static> IntoAnyElement<V> for String {
fn into_any(self) -> AnyElement<V> {
Text {
text: self.into(),
state_type: PhantomData,
@@ -44,13 +44,16 @@ pub struct Text<V> {
state_type: PhantomData<V>,
}
impl<V: 'static + Send + Sync> IntoAnyElement<V> for Text<V> {
unsafe impl<V> Send for Text<V> {}
unsafe impl<V> Sync for Text<V> {}
impl<V: 'static> IntoAnyElement<V> for Text<V> {
fn into_any(self) -> AnyElement<V> {
AnyElement::new(self)
}
}
impl<V: 'static + Send + Sync> Element for Text<V> {
impl<V: 'static> Element for Text<V> {
type ViewState = V;
type ElementState = Arc<Mutex<Option<TextElementState>>>;