diff --git a/leptos/src/callback.rs b/leptos/src/callback.rs index 6a4973ab5..f095133b9 100644 --- a/leptos/src/callback.rs +++ b/leptos/src/callback.rs @@ -31,15 +31,15 @@ //! *Notes*: //! - The `render_number` prop can receive any type that implements `Fn(i32) -> String`. //! - Callbacks are most useful when you want optional generic props. -//! - All callbacks implement the [`Callable`] trait, and can be invoked with `my_callback.call(input)`. On nightly, you can even do `my_callback(input)` +//! - All callbacks implement the [`Callable`] trait, and can be invoked with `my_callback.run(input)`. //! - The callback types implement [`Copy`], so they can easily be moved into and out of other closures, just like signals. //! //! # Types //! This modules implements 2 callback types: //! - [`Callback`] -//! - [`SyncCallback`] +//! - [`UnsyncCallback`] //! -//! Use `SyncCallback` when you want the function to be `Sync` and `Send`. +//! Use `SyncCallback` if the function is not `Sync` and `Send`. use reactive_graph::owner::StoredValue; use std::{fmt, rc::Rc, sync::Arc}; @@ -83,64 +83,14 @@ impl Callable for UnsyncCallback { } } -macro_rules! impl_from_fn { - ($ty:ident) => { - #[cfg(not(feature = "nightly"))] - impl From for $ty - where - F: Fn(In) -> T + Send + Sync + 'static, - T: Into + 'static, - In: Send + Sync + 'static, - { - fn from(f: F) -> Self { - Self::new(move |x| f(x).into()) - } - } - - paste::paste! { - #[cfg(feature = "nightly")] - auto trait [] {} - - #[cfg(feature = "nightly")] - impl ![] for $ty {} - - #[cfg(feature = "nightly")] - impl From for $ty - where - F: Fn(In) -> T + Send + Sync + [] + 'static, - T: Into + 'static, - In: Send + Sync + 'static - { - fn from(f: F) -> Self { - Self::new(move |x| f(x).into()) - } - } - } - }; -} - -impl_from_fn!(UnsyncCallback); - -#[cfg(feature = "nightly")] -impl FnOnce<(In,)> for UnsyncCallback { - type Output = Out; - - extern "rust-call" fn call_once(self, args: (In,)) -> Self::Output { - Callable::call(&self, args.0) - } -} - -#[cfg(feature = "nightly")] -impl FnMut<(In,)> for UnsyncCallback { - extern "rust-call" fn call_mut(&mut self, args: (In,)) -> Self::Output { - Callable::call(&*self, args.0) - } -} - -#[cfg(feature = "nightly")] -impl Fn<(In,)> for UnsyncCallback { - extern "rust-call" fn call(&self, args: (In,)) -> Self::Output { - Callable::call(self, args.0) +impl From for UnsyncCallback +where + F: Fn(In) -> T + 'static, + T: Into + 'static, + In: 'static, +{ + fn from(f: F) -> Self { + Self::new(move |x| f(x).into()) } } @@ -196,6 +146,17 @@ impl Clone for Callback { impl Copy for Callback {} +impl From for Callback +where + F: Fn(In) -> T + Send + Sync + 'static, + T: Into + 'static, + In: Send + Sync + 'static, +{ + fn from(f: F) -> Self { + Self::new(move |x| f(x).into()) + } +} + impl Callback { /// Creates a new callback from the given function. pub fn new(fun: F) -> Self @@ -206,43 +167,6 @@ impl Callback { } } -impl_from_fn!(Callback); - -#[cfg(feature = "nightly")] -impl FnOnce<(In,)> for Callback -where - In: Send + Sync + 'static, - Out: 'static, -{ - type Output = Out; - - extern "rust-call" fn call_once(self, args: (In,)) -> Self::Output { - Callable::call(&self, args.0) - } -} - -#[cfg(feature = "nightly")] -impl FnMut<(In,)> for Callback -where - In: Send + Sync + 'static, - Out: 'static, -{ - extern "rust-call" fn call_mut(&mut self, args: (In,)) -> Self::Output { - Callable::call(&*self, args.0) - } -} - -#[cfg(feature = "nightly")] -impl Fn<(In,)> for Callback -where - In: Send + Sync + 'static, - Out: 'static, -{ - extern "rust-call" fn call(&self, args: (In,)) -> Self::Output { - Callable::call(self, args.0) - } -} - #[cfg(test)] mod tests { use crate::callback::{Callback, UnsyncCallback}; diff --git a/leptos/src/lib.rs b/leptos/src/lib.rs index 2aad22f8a..d58bc8878 100644 --- a/leptos/src/lib.rs +++ b/leptos/src/lib.rs @@ -142,8 +142,6 @@ #![cfg_attr(feature = "nightly", feature(fn_traits))] #![cfg_attr(feature = "nightly", feature(unboxed_closures))] -#![cfg_attr(feature = "nightly", feature(auto_traits))] -#![cfg_attr(feature = "nightly", feature(negative_impls))] extern crate self as leptos;