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

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