diff --git a/crates/react-html/src/macros/props.rs b/crates/react-html/src/macros/props.rs index 49d49311..a7da62f2 100644 --- a/crates/react-html/src/macros/props.rs +++ b/crates/react-html/src/macros/props.rs @@ -13,8 +13,8 @@ macro_rules! __impl_prop_default { { event_handler } ) => { $($attr)* - fn $k (mut self, event_handler: Option>) -> Self - where react::WrapFn: react::event::IntoJsEventHandler<$v_ty> + fn $k (mut self, event_handler: Option>) -> Self + where react::AnyFn: react::event::IntoJsEventHandler<$v_ty> { if let Some(event_handler) = event_handler { let ret = react::event::IntoJsEventHandler::into_js_event_handler(event_handler); diff --git a/crates/react/src/any_fn_family/any_fn.rs b/crates/react/src/any_fn_family/any_fn.rs new file mode 100644 index 00000000..99f8ac56 --- /dev/null +++ b/crates/react/src/any_fn_family/any_fn.rs @@ -0,0 +1,125 @@ +use std::{any::Any, rc::Rc}; +use wasm_bindgen::closure::{Closure, WasmClosure}; + +use crate::{DynFn, FnOfArgs, IntoPropValue}; + +pub struct AnyFn(pub Rc) +where + F: ?Sized + DynFn; + +impl AnyFn { + #[inline] + pub fn inner(&self) -> &Rc { + &self.0 + } + + #[inline] + pub fn into_inner(self) -> Rc { + self.0 + } + + #[inline] + pub fn new< + TFunc: 'static + ?Sized + FnOfArgs, + RF: crate::IntoRc, + >( + func: RF, + ) -> Self { + let func: Rc = func.into_rc(); + let func = func.into_rc_dyn_fn(); + Self(func) + } +} + +impl std::ops::Deref for AnyFn { + type Target = Rc; + + #[inline] + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl AsRef> for AnyFn { + #[inline] + fn as_ref(&self) -> &Rc { + &self.0 + } +} + +impl Clone for AnyFn { + #[inline] + fn clone(&self) -> Self { + Self(self.0.clone()) + } +} + +impl std::fmt::Debug for AnyFn { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "AnyFn<{}>", std::any::type_name::()) + } +} + +impl crate::SafeIntoJsRuntime for AnyFn +where + F: 'static + WasmClosure, +{ + fn safe_into_js_runtime(self) -> crate::PassedToJsRuntime { + let boxed = self.0.rc_into_box_dyn_fn(); + + let closure = Closure::wrap(boxed); + let js_value = closure.as_ref().clone(); + crate::PassedToJsRuntime { + js_value, + to_persist: Some(Box::new(closure) as Box), + } + } +} + +impl> + IntoPropValue> for Rc +{ + fn into_prop_value(self) -> AnyFn { + AnyFn(self.into_rc_dyn_fn()) + } +} + +impl> + IntoPropValue>> for Rc +{ + fn into_prop_value(self) -> Option> { + Some(self.into_prop_value()) + } +} + +impl> + IntoPropValue>> for Option> +{ + fn into_prop_value(self) -> Option> { + self.map(IntoPropValue::into_prop_value) + } +} + +impl> + IntoPropValue> for &Rc +{ + fn into_prop_value(self) -> AnyFn { + AnyFn(Rc::clone(self).into_rc_dyn_fn()) + } +} + +impl> + IntoPropValue>> for &Rc +{ + fn into_prop_value(self) -> Option> { + Some(self.into_prop_value()) + } +} + +impl> + IntoPropValue>> for Option<&Rc> +{ + fn into_prop_value(self) -> Option> { + self.map(IntoPropValue::into_prop_value) + } +} diff --git a/crates/react/src/any_fn_family/any_fn_mut.rs b/crates/react/src/any_fn_family/any_fn_mut.rs new file mode 100644 index 00000000..6caad715 --- /dev/null +++ b/crates/react/src/any_fn_family/any_fn_mut.rs @@ -0,0 +1,68 @@ +use std::any::Any; +use wasm_bindgen::closure::{Closure, WasmClosure}; + +use crate::{DynFnMut, FnMutOfArgs}; + +pub struct AnyFnMut(pub Box) +where + F: ?Sized + DynFnMut; + +impl AnyFnMut { + #[inline] + pub fn inner(&self) -> &Box { + &self.0 + } + + #[inline] + pub fn into_inner(self) -> Box { + self.0 + } + + #[inline] + pub fn new< + TFunc: 'static + ?Sized + FnMutOfArgs, + BF: crate::IntoBoxed, + >( + func: BF, + ) -> Self { + let func: Box = func.into_boxed(); + let func = func.into_box_dyn_fn_mut(); + Self(func) + } +} + +impl std::ops::Deref for AnyFnMut { + type Target = Box; + + #[inline] + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl AsRef> for AnyFnMut { + #[inline] + fn as_ref(&self) -> &Box { + &self.0 + } +} + +impl std::fmt::Debug for AnyFnMut { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "AnyFnMut<{}>", std::any::type_name::()) + } +} + +impl crate::SafeIntoJsRuntime for AnyFnMut +where + F: 'static + WasmClosure, +{ + fn safe_into_js_runtime(self) -> crate::PassedToJsRuntime { + let closure = Closure::wrap(self.0); + let js_value = closure.as_ref().clone(); + crate::PassedToJsRuntime { + js_value, + to_persist: Some(Box::new(closure) as Box), + } + } +} diff --git a/crates/react/src/any_fn_family/any_fn_once.rs b/crates/react/src/any_fn_family/any_fn_once.rs new file mode 100644 index 00000000..39454be5 --- /dev/null +++ b/crates/react/src/any_fn_family/any_fn_once.rs @@ -0,0 +1,69 @@ +use std::any::Any; +use wasm_bindgen::closure::{Closure, WasmClosureFnOnce}; + +use crate::{DynFnOnce, FnOnceOfArgs}; + +pub struct AnyFnOnce(pub Box) +where + F: ?Sized + DynFnOnce; + +impl AnyFnOnce { + #[inline] + pub fn inner(&self) -> &Box { + &self.0 + } + + #[inline] + pub fn into_inner(self) -> Box { + self.0 + } + + #[inline] + pub fn new< + TFunc: 'static + ?Sized + FnOnceOfArgs, + BF: crate::IntoBoxed, + >( + func: BF, + ) -> Self { + let func: Box = func.into_boxed(); + let func = func.into_box_dyn_fn_once(); + Self(func) + } +} + +impl std::ops::Deref for AnyFnOnce { + type Target = Box; + + #[inline] + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl AsRef> for AnyFnOnce { + #[inline] + fn as_ref(&self) -> &Box { + &self.0 + } +} + +impl std::fmt::Debug for AnyFnOnce { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "AnyFnOnce<{}>", std::any::type_name::()) + } +} + +impl crate::SafeIntoJsRuntime for AnyFnOnce +where + F: 'static, + Box: WasmClosureFnOnce, +{ + fn safe_into_js_runtime(self) -> crate::PassedToJsRuntime { + let closure = Closure::once(self.0); + let js_value = closure.as_ref().clone(); + crate::PassedToJsRuntime { + js_value, + to_persist: Some(Box::new(closure) as Box), + } + } +} diff --git a/crates/react/src/any_fn_family/fn_of_args.rs b/crates/react/src/any_fn_family/fn_of_args.rs new file mode 100644 index 00000000..fee11b80 --- /dev/null +++ b/crates/react/src/any_fn_family/fn_of_args.rs @@ -0,0 +1,289 @@ +use std::rc::Rc; + +pub trait DynFn: FnOfArgs { + type ArgsTuple; +} + +pub trait DynFnMut: FnMutOfArgs { + type ArgsTuple; +} + +pub trait DynFnOnce: FnOnceOfArgs { + type ArgsTuple; +} + +pub trait FnOfArgs: FnMutOfArgs { + type DynFn: ?Sized + DynFn; + + fn into_rc_dyn_fn(self: Rc) -> Rc + where + Self: 'static; + fn rc_into_box_dyn_fn(self: Rc) -> Box + where + Self: 'static; + fn into_box_dyn_fn(self: Box) -> Box + where + Self: 'static; +} + +pub trait FnMutOfArgs: FnOnceOfArgs { + type DynFnMut: ?Sized + DynFnMut; + + fn into_box_dyn_fn_mut(self: Box) -> Box + where + Self: 'static; +} + +pub trait FnOnceOfArgs { + type Output; + type DynFnOnce: ?Sized + DynFnOnce; + + fn into_box_dyn_fn_once(self: Box) -> Box + where + Self: 'static; +} + +macro_rules! doit { + ($( + ($($var:ident)*) + )*) => ($( + impl<$($var,)* TReturn> DynFn for dyn Fn($($var,)*) -> TReturn { + type ArgsTuple = ($($var,)*); + } + + impl<$($var,)* TReturn> DynFnMut for dyn FnMut($($var,)*) -> TReturn { + type ArgsTuple = ($($var,)*); + } + + impl<$($var,)* TReturn> DynFnOnce for dyn FnOnce($($var,)*) -> TReturn { + type ArgsTuple = ($($var,)*); + } + + impl FnOnceOfArgs<($($var,)*)> for TFunc + where TFunc: FnOnce($($var),*) -> TReturn + { + type Output = TReturn; + type DynFnOnce = dyn FnOnce($($var,)*) -> TReturn; + + #[inline] + fn into_box_dyn_fn_once(self: Box) -> Box + where + Self: 'static, + { + self as Box + } + } + + impl<$($var,)* TReturn> FnOnceOfArgs<($($var,)*)> for dyn FnOnce($($var),*) -> TReturn { + type Output = TReturn; + type DynFnOnce = Self; + + #[inline] + fn into_box_dyn_fn_once(self: Box) -> Box + where + Self: 'static, + { + self + } + } + + impl<$($var,)* TReturn> FnOnceOfArgs<($($var,)*)> for dyn FnMut($($var),*) -> TReturn { + type Output = TReturn; + type DynFnOnce = dyn FnOnce($($var,)*) -> TReturn; + + #[inline] + fn into_box_dyn_fn_once(self: Box) -> Box + where + Self: 'static, + { + Box::new(self) as Box + } + } + + impl<$($var,)* TReturn> FnOnceOfArgs<($($var,)*)> for dyn Fn($($var),*) -> TReturn { + type Output = TReturn; + type DynFnOnce = dyn FnOnce($($var,)*) -> TReturn; + + #[inline] + fn into_box_dyn_fn_once(self: Box) -> Box + where + Self: 'static, + { + Box::new(self) as Box + } + } + + impl FnMutOfArgs<($($var,)*)> for TFunc + where TFunc: FnMut($($var),*) -> TReturn + { + type DynFnMut = dyn FnMut($($var,)*) -> TReturn; + + #[inline] + fn into_box_dyn_fn_mut(self: Box) -> Box + where + Self: 'static, + { + self as Box + } + } + + impl<$($var,)* TReturn> FnMutOfArgs<($($var,)*)> for dyn FnMut($($var),*) -> TReturn { + type DynFnMut = Self; + + #[inline] + fn into_box_dyn_fn_mut(self: Box) -> Box + where + Self: 'static, + { + self + } + } + + impl<$($var,)* TReturn> FnMutOfArgs<($($var,)*)> for dyn Fn($($var),*) -> TReturn { + type DynFnMut = dyn FnMut($($var,)*) -> TReturn; + + #[inline] + fn into_box_dyn_fn_mut(self: Box) -> Box + where + Self: 'static, + { + Box::new(self) as Box + } + } + + impl FnOfArgs<($($var,)*)> for TFunc + where TFunc: Fn($($var),*) -> TReturn + { + type DynFn = dyn Fn($($var,)*) -> TReturn; + + #[inline] + fn into_rc_dyn_fn(self: Rc) -> Rc + where + Self: 'static, + { + self as Rc + } + + #[inline] + fn rc_into_box_dyn_fn(self: Rc) -> Box + where + Self: 'static, + { + #![allow(non_snake_case)] + Box::new(move |$($var: $var),*| (*self)($($var),*)) as Box + } + + #[inline] + fn into_box_dyn_fn(self: Box) -> Box + where + Self: 'static, + { + self as Box + } + } + + impl<$($var,)* TReturn> FnOfArgs<($($var,)*)> for dyn Fn($($var),*) -> TReturn { + type DynFn = Self; + + #[inline] + fn into_rc_dyn_fn(self: Rc) -> Rc + where + Self: 'static, + { + self as Rc + } + + #[inline] + fn rc_into_box_dyn_fn(self: Rc) -> Box + where + Self: 'static, + { + #![allow(non_snake_case)] + Box::new(move |$($var: $var),*| (*self)($($var),*)) as Box + } + + #[inline] + fn into_box_dyn_fn(self: Box) -> Box + where + Self: 'static, + { + self as Box + } + } + + impl TReturn, TReturn, $($var,)*> $crate::IntoPropValue<$crate::AnyFn TReturn>> for TFunc { + #[inline] + fn into_prop_value(self) -> $crate::AnyFn TReturn> { + $crate::AnyFn::new(self) + } + } + + impl TReturn, TReturn, $($var,)*> $crate::IntoPropValue TReturn>>> for TFunc { + #[inline] + fn into_prop_value(self) -> Option<$crate::AnyFn TReturn>> { + Some($crate::AnyFn::new(self)) + } + } + + impl TReturn, TReturn, $($var,)*> $crate::IntoPropValue TReturn>>> for Option { + #[inline] + fn into_prop_value(self) -> Option<$crate::AnyFn TReturn>> { + self.map($crate::IntoPropValue::into_prop_value) + } + } + + impl TReturn, TReturn, $($var,)*> $crate::IntoPropValue<$crate::AnyFnMut TReturn>> for TFunc { + #[inline] + fn into_prop_value(self) -> $crate::AnyFnMut TReturn> { + $crate::AnyFnMut::new(self) + } + } + + impl TReturn, TReturn, $($var,)*> $crate::IntoPropValue TReturn>>> for TFunc { + #[inline] + fn into_prop_value(self) -> Option<$crate::AnyFnMut TReturn>> { + Some($crate::AnyFnMut::new(self)) + } + } + + impl TReturn, TReturn, $($var,)*> $crate::IntoPropValue TReturn>>> for Option { + #[inline] + fn into_prop_value(self) -> Option<$crate::AnyFnMut TReturn>> { + self.map($crate::IntoPropValue::into_prop_value) + } + } + + impl TReturn, TReturn, $($var,)*> $crate::IntoPropValue<$crate::AnyFnOnce TReturn>> for TFunc { + #[inline] + fn into_prop_value(self) -> $crate::AnyFnOnce TReturn> { + $crate::AnyFnOnce::new(self) + } + } + + impl TReturn, TReturn, $($var,)*> $crate::IntoPropValue TReturn>>> for TFunc { + #[inline] + fn into_prop_value(self) -> Option<$crate::AnyFnOnce TReturn>> { + Some($crate::AnyFnOnce::new(self)) + } + } + + impl TReturn, TReturn, $($var,)*> $crate::IntoPropValue TReturn>>> for Option { + #[inline] + fn into_prop_value(self) -> Option<$crate::AnyFnOnce TReturn>> { + self.map($crate::IntoPropValue::into_prop_value) + } + } + )*) +} + +doit! { + () + (A) + (A B) + (A B C) + (A B C D) + (A B C D E) + (A B C D E F) + (A B C D E F G) + (A B C D E F G H) +} diff --git a/crates/react/src/any_fn_family/mod.rs b/crates/react/src/any_fn_family/mod.rs new file mode 100644 index 00000000..24e3a425 --- /dev/null +++ b/crates/react/src/any_fn_family/mod.rs @@ -0,0 +1,9 @@ +mod any_fn; +mod any_fn_mut; +mod any_fn_once; +mod fn_of_args; + +pub use any_fn::*; +pub use any_fn_mut::*; +pub use any_fn_once::*; +pub use fn_of_args::*; diff --git a/crates/react/src/event/handlers.rs b/crates/react/src/event/handlers.rs index e76cebbb..4d5b6b3f 100644 --- a/crates/react/src/event/handlers.rs +++ b/crates/react/src/event/handlers.rs @@ -7,9 +7,9 @@ //! # use react::{IntoPropValue, event::{ IntoJsEventHandler, MouseEvent }}; //! # struct MyPropsBuilder; //! # impl MyPropsBuilder { -//! # fn on_click(&self, _handler: Option>) +//! # fn on_click(&self, _handler: Option>) //! # where -//! # react::WrapFn: IntoJsEventHandler {} +//! # react::AnyFn: IntoJsEventHandler {} //! # } //! # let builder = MyPropsBuilder; //! # builder.on_click(IntoPropValue::into_prop_value( @@ -57,20 +57,21 @@ pub trait IntoJsEventHandler { } /// `Fn()` can be handlers for any event -impl IntoJsEventHandler for crate::WrapFn { +impl IntoJsEventHandler for crate::AnyFn { + #[inline] fn into_js_event_handler(self) -> crate::PassedToJsRuntime { self.safe_into_js_runtime() } } /// `Fn(TEvent)` can be handlers for `TEvent` -impl IntoJsEventHandler - for crate::WrapFn +impl IntoJsEventHandler for crate::AnyFn where TEvent::Error: std::fmt::Debug, { + #[inline] fn into_js_event_handler(self) -> crate::PassedToJsRuntime { - crate::WrapFn::new(move |js_value: wasm_bindgen::JsValue| { + crate::AnyFn::new(move |js_value: wasm_bindgen::JsValue| { let event = TEvent::from_js(js_value).unwrap_throw(); (self.0.as_ref())(event); }) diff --git a/crates/react/src/into_boxed.rs b/crates/react/src/into_boxed.rs new file mode 100644 index 00000000..035ca23a --- /dev/null +++ b/crates/react/src/into_boxed.rs @@ -0,0 +1,17 @@ +pub trait IntoBoxed { + fn into_boxed(self) -> Box; +} + +impl IntoBoxed for T { + #[inline] + fn into_boxed(self) -> Box { + Box::new(self) + } +} + +impl IntoBoxed for Box { + #[inline] + fn into_boxed(self) -> Box { + self + } +} diff --git a/crates/react/src/lib.rs b/crates/react/src/lib.rs index 3bbdd13e..5bb0e2bf 100644 --- a/crates/react/src/lib.rs +++ b/crates/react/src/lib.rs @@ -1,10 +1,12 @@ // mod use_closure; mod take_rc; // mod use_closure; +mod any_fn_family; mod common_props; mod component; mod element; mod fragment; +mod into_boxed; mod into_prop_value; mod key; mod node; @@ -16,10 +18,12 @@ mod use_memo; mod use_ref; mod use_state; +pub use any_fn_family::*; pub use common_props::*; pub use component::*; pub use element::*; pub use fragment::*; +pub use into_boxed::*; pub use into_prop_value::*; pub use key::*; pub use node::*; diff --git a/crates/react/src/node/any.rs b/crates/react/src/node/any.rs index 7ea888af..b3d03396 100644 --- a/crates/react/src/node/any.rs +++ b/crates/react/src/node/any.rs @@ -55,3 +55,28 @@ impl AnyNode { js } } + +impl Node for AnyNode { + #[inline] + fn to_node(&self) -> AnyNode { + self.clone() + } + + #[inline] + fn to_children(&self) -> Option { + Some(crate::Children::from_single(self.clone())) + } + + #[inline] + fn into_node(self) -> AnyNode { + self + } + + #[inline] + fn into_children(self) -> Option + where + Self: Sized, + { + Some(crate::Children::from_single(self)) + } +} diff --git a/crates/react/src/safe_into_js/closure.rs b/crates/react/src/safe_into_js/closure.rs deleted file mode 100644 index 23910caa..00000000 --- a/crates/react/src/safe_into_js/closure.rs +++ /dev/null @@ -1,289 +0,0 @@ -//! [`Closure`] -//! [`WrapFn`] -//! [`WrapFnMut`] -//! [`WrapFnOnce`] -//! [`WrapDynFnOrFnMut`] -//! [`WrapDynFnOrFnMut`] -//! implements [`SafeIntoJsRuntime`]. - -use super::{PassedToJsRuntime, SafeIntoJsRuntime}; -use std::{any::Any, marker::PhantomData, rc::Rc}; -use wasm_bindgen::closure::{Closure, WasmClosure, WasmClosureFnOnce}; - -pub struct WrapFn(pub Rc, PhantomData); -pub struct WrapFnMut(pub F, PhantomData); -pub struct WrapFnOnce(pub F, PhantomData<(TArgs, TReturn)>); -pub struct WrapDynFnOrFnMut(pub Box); - -impl WrapFn { - #[inline] - pub fn new>(func: RF) -> WrapFn - where - WrapFn: SafeIntoJsRuntime, - { - let func: Rc = func.into_rc(); - WrapFn(func, PhantomData) - } -} - -impl Clone for WrapFn { - fn clone(&self) -> Self { - Self(self.0.clone(), PhantomData) - } -} - -impl std::fmt::Debug for WrapFn { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "WrapFn<{}>", std::any::type_name::()) - } -} - -impl WrapFnMut { - #[inline] - pub fn new(func: F) -> WrapFnMut - where - WrapFnMut: SafeIntoJsRuntime, - { - WrapFnMut(func, PhantomData) - } -} - -impl WrapDynFnOrFnMut { - #[inline] - pub fn new(func: Box) -> Self { - Self(func) - } -} - -impl WrapFnOnce { - #[inline] - pub fn new(func: F) -> WrapFnOnce - where - F: WasmClosureFnOnce, - { - WrapFnOnce(func, PhantomData) - } -} - -/// Closure -impl SafeIntoJsRuntime for Closure { - #[inline] - fn safe_into_js_runtime(self) -> PassedToJsRuntime { - own_closure(self) - } -} - -impl SafeIntoJsRuntime for WrapDynFnOrFnMut { - #[inline] - fn safe_into_js_runtime(self) -> PassedToJsRuntime { - own_fn(self.0) - } -} - -impl, A, R> SafeIntoJsRuntime for WrapFnOnce { - #[inline] - fn safe_into_js_runtime(self) -> PassedToJsRuntime { - own_fn_once(self.0) - } -} - -impl crate::IntoPropValue> for Box { - fn into_prop_value(self) -> WrapDynFnOrFnMut { - WrapDynFnOrFnMut(self) - } -} - -fn own_fn_once, A, R>(func: F) -> PassedToJsRuntime { - let c = Closure::once(func); - own_closure(c) -} - -fn own_fn(v: Box) -> PassedToJsRuntime -where - T: ?Sized + WasmClosure, -{ - let c = Closure::wrap(v); - own_closure(c) -} - -fn own_closure(v: Closure) -> PassedToJsRuntime { - let js_value = v.as_ref().clone(); - PassedToJsRuntime { - js_value, - to_persist: Some(Box::new(v) as Box), - } -} - -macro_rules! doit { - ($( - ($($var:ident)*) - )*) => ($( - #[doc = concat!("WrapFn TR>")] - impl SafeIntoJsRuntime for WrapFn - where $($var: 'static,)* - R: 'static, - TFunc: Fn($($var),*) -> R + 'static, - dyn Fn($($var),*) -> R: WasmClosure, - { - #[inline] - fn safe_into_js_runtime(self) -> PassedToJsRuntime { - #[allow(non_snake_case)] - own_fn(Box::new(move |$($var,)*| (self.0)($($var,)*) ) as Box R>) - } - } - - #[doc = concat!("WrapFnMut TR>")] - impl SafeIntoJsRuntime for WrapFnMut - where $($var: 'static,)* - R: 'static, - TFunc: Fn($($var),*) -> R + 'static, - dyn FnMut($($var),*) -> R: WasmClosure, - { - #[inline] - fn safe_into_js_runtime(self) -> PassedToJsRuntime { - own_fn(Box::new(self.0) as Box R>) - } - } - - impl $crate::IntoPropValue> for TFunc - where TFunc: Fn($($var),*) -> R - { - #[inline] - fn into_prop_value(self) -> WrapFn { - WrapFn(Rc::new(self), PhantomData) - } - } - - impl $crate::IntoPropValue> for Rc - where TFunc: Fn($($var),*) -> R - { - #[inline] - fn into_prop_value(self) -> WrapFn { - WrapFn(self, PhantomData) - } - } - - impl $crate::IntoPropValue> for &Rc - where TFunc: Fn($($var),*) -> R - { - #[inline] - fn into_prop_value(self) -> WrapFn { - WrapFn(Rc::clone(self), PhantomData) - } - } - - impl $crate::IntoPropValue>> for TFunc - where TFunc: Fn($($var),*) -> R - { - #[inline] - fn into_prop_value(self) -> Option> { - Some(WrapFn(Rc::new(self), PhantomData)) - } - } - - impl $crate::IntoPropValue>> for Option - where TFunc: Fn($($var),*) -> R - { - #[inline] - fn into_prop_value(self) -> Option> { - self.map(crate::IntoPropValue::into_prop_value) - } - } - - impl $crate::IntoPropValue>> for Rc - where TFunc: Fn($($var),*) -> R - { - #[inline] - fn into_prop_value(self) -> Option> { - Some(WrapFn(self, PhantomData)) - } - } - - impl $crate::IntoPropValue>> for Option> - where TFunc: Fn($($var),*) -> R - { - #[inline] - fn into_prop_value(self) -> Option> { - self.map(crate::IntoPropValue::into_prop_value) - } - } - - impl $crate::IntoPropValue>> for &Rc - where TFunc: Fn($($var),*) -> R - { - #[inline] - fn into_prop_value(self) -> Option> { - Some(WrapFn(Rc::clone(self), PhantomData)) - } - } - - impl $crate::IntoPropValue>> for Option<&Rc> - where TFunc: Fn($($var),*) -> R - { - #[inline] - fn into_prop_value(self) -> Option> { - self.map(crate::IntoPropValue::into_prop_value) - } - } - - impl $crate::IntoPropValue> for TFunc - where TFunc: FnMut($($var),*) -> R - { - fn into_prop_value(self) -> WrapFnMut { - WrapFnMut(self, PhantomData) - } - } - - impl $crate::IntoPropValue>> for TFunc - where TFunc: FnMut($($var),*) -> R - { - fn into_prop_value(self) -> Option> { - Some(WrapFnMut(self, PhantomData)) - } - } - - impl $crate::IntoPropValue>> for Option - where TFunc: FnMut($($var),*) -> R - { - fn into_prop_value(self) -> Option> { - self.map(crate::IntoPropValue::into_prop_value) - } - } - - impl $crate::IntoPropValue> for TFunc - where TFunc: FnOnce($($var),*) -> R - { - fn into_prop_value(self) -> WrapFnOnce { - WrapFnOnce(self, PhantomData) - } - } - - impl $crate::IntoPropValue>> for TFunc - where TFunc: FnOnce($($var),*) -> R - { - fn into_prop_value(self) -> Option> { - Some(WrapFnOnce(self, PhantomData)) - } - } - - impl $crate::IntoPropValue>> for Option - where TFunc: FnOnce($($var),*) -> R - { - fn into_prop_value(self) -> Option> { - self.map(crate::IntoPropValue::into_prop_value) - } - } - )*) -} - -doit! { - () - (A) - (A B) - (A B C) - (A B C D) - (A B C D E) - (A B C D E F) - (A B C D E F G) - (A B C D E F G H) -} diff --git a/crates/react/src/safe_into_js/mod.rs b/crates/react/src/safe_into_js/mod.rs index d57c3578..ea11103c 100644 --- a/crates/react/src/safe_into_js/mod.rs +++ b/crates/react/src/safe_into_js/mod.rs @@ -1,5 +1,3 @@ -mod closure; mod data; -pub use closure::*; pub use data::*; diff --git a/crates/react/src/use_ref/use_ref.rs b/crates/react/src/use_ref/use_ref.rs index 6294f6ab..78b8795a 100644 --- a/crates/react/src/use_ref/use_ref.rs +++ b/crates/react/src/use_ref/use_ref.rs @@ -89,7 +89,7 @@ where T: 'static, { fn safe_into_js_runtime(self) -> crate::PassedToJsRuntime { - crate::WrapFn::new(move |v| self.set_current(v)).safe_into_js_runtime() + crate::AnyFn::new(move |v| self.set_current(v)).safe_into_js_runtime() } }