Merge branch 'main' into fix/use_scroll

This commit is contained in:
Jens Krause 2023-07-13 08:23:02 +02:00
commit 399614879a
10 changed files with 222 additions and 172 deletions

View file

@ -454,7 +454,6 @@ pub struct UseStorageOptions<T> {
/// Defaults to simply returning the stored value.
pub(crate) merge_defaults: fn(&str, &T) -> String,
/// Optional callback whenever an error occurs. The callback takes an argument of type [`UseStorageError`].
#[builder(into)]
pub(crate) on_error: Box<dyn CloneableFnWithArg<UseStorageError>>,
/// Debounce or throttle the writing to storage whenever the value changes.

View file

@ -379,7 +379,6 @@ where
/// Custom handler that is called on updates.
/// If specified this will override the default behavior.
/// To get the default behaviour back you can call the provided `default_handler` function.
#[builder(into)]
on_changed: Box<dyn CloneableFnWithArg<UseColorModeOnChangeArgs>>,
/// When provided, `useStorage` will be skipped.

View file

@ -92,7 +92,6 @@ pub struct UseIntervalOptions {
immediate: bool,
/// Callback on every interval.
#[builder(into)]
callback: Box<dyn CloneableFnWithArg<u64>>,
}

View file

@ -1,169 +0,0 @@
use std::fmt::Debug;
pub trait CloneableFnWithReturn<R>: FnOnce() -> R {
fn clone_box(&self) -> Box<dyn CloneableFnWithReturn<R>>;
}
impl<F, R> CloneableFnWithReturn<R> for F
where
F: FnOnce() -> R + Clone + 'static,
R: 'static,
{
fn clone_box(&self) -> Box<dyn CloneableFnWithReturn<R>> {
Box::new(self.clone())
}
}
impl<R> Clone for Box<dyn CloneableFnWithReturn<R>> {
fn clone(&self) -> Self {
(**self).clone_box()
}
}
impl<R: Default + 'static> Default for Box<dyn CloneableFnWithReturn<R>> {
fn default() -> Self {
Box::new(|| Default::default())
}
}
pub trait CloneableFnWithArgAndReturn<Arg, R>: FnOnce(Arg) -> R {
fn clone_box(&self) -> Box<dyn CloneableFnWithArgAndReturn<Arg, R>>;
}
impl<F, R, Arg> CloneableFnWithArgAndReturn<Arg, R> for F
where
F: FnMut(Arg) -> R + Clone + 'static,
R: 'static,
{
fn clone_box(&self) -> Box<dyn CloneableFnWithArgAndReturn<Arg, R>> {
Box::new(self.clone())
}
}
impl<R, Arg> Clone for Box<dyn CloneableFnWithArgAndReturn<Arg, R>> {
fn clone(&self) -> Self {
(**self).clone_box()
}
}
impl<R: Default + 'static, Arg> Default for Box<dyn CloneableFnWithArgAndReturn<Arg, R>> {
fn default() -> Self {
Box::new(|_| Default::default())
}
}
pub trait CloneableFn: FnOnce() {
fn clone_box(&self) -> Box<dyn CloneableFn>;
}
impl<F> CloneableFn for F
where
F: FnOnce() + Clone + 'static,
{
fn clone_box(&self) -> Box<dyn CloneableFn> {
Box::new(self.clone())
}
}
impl Clone for Box<dyn CloneableFn> {
fn clone(&self) -> Self {
(**self).clone_box()
}
}
impl Default for Box<dyn CloneableFn> {
fn default() -> Self {
Box::new(|| {})
}
}
pub trait CloneableFnWithArg<Arg>: FnOnce(Arg) {
fn clone_box(&self) -> Box<dyn CloneableFnWithArg<Arg>>;
}
impl<F, Arg> CloneableFnWithArg<Arg> for F
where
F: FnMut(Arg) + Clone + 'static,
{
fn clone_box(&self) -> Box<dyn CloneableFnWithArg<Arg>> {
Box::new(self.clone())
}
}
impl<Arg> Clone for Box<dyn CloneableFnWithArg<Arg>> {
fn clone(&self) -> Self {
(**self).clone_box()
}
}
impl<Arg> Default for Box<dyn CloneableFnWithArg<Arg>> {
fn default() -> Self {
Box::new(|_| {})
}
}
pub trait CloneableFnMutWithArg<Arg>: FnMut(Arg) {
fn clone_box(&self) -> Box<dyn CloneableFnMutWithArg<Arg>>;
}
impl<F, Arg> CloneableFnMutWithArg<Arg> for F
where
F: FnMut(Arg) + Clone + 'static,
{
fn clone_box(&self) -> Box<dyn CloneableFnMutWithArg<Arg>> {
Box::new(self.clone())
}
}
impl<Arg> Clone for Box<dyn CloneableFnMutWithArg<Arg>> {
fn clone(&self) -> Self {
(**self).clone_box()
}
}
impl<Arg> Default for Box<dyn CloneableFnMutWithArg<Arg>> {
fn default() -> Self {
Box::new(|_| {})
}
}
impl<Arg> Debug for Box<dyn CloneableFnMutWithArg<Arg>> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Box<dyn CloneableFnMutWithArg<{}>>",
std::any::type_name::<Arg>()
)
}
}
pub trait CloneableFnMut: FnMut() {
fn clone_box(&self) -> Box<dyn CloneableFnMut>;
}
impl<F> CloneableFnMut for F
where
F: FnMut() + Clone + 'static,
{
fn clone_box(&self) -> Box<dyn CloneableFnMut> {
Box::new(self.clone())
}
}
impl Clone for Box<dyn CloneableFnMut> {
fn clone(&self) -> Self {
(**self).clone_box()
}
}
impl Default for Box<dyn CloneableFnMut> {
fn default() -> Self {
Box::new(|| {})
}
}
impl Debug for Box<dyn CloneableFnMut> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Box<dyn CloneableFnMut>",)
}
}

View file

@ -0,0 +1,43 @@
mod mut_;
mod mut_with_arg;
mod with_arg;
mod with_arg_and_return;
mod with_return;
pub use mut_::*;
pub use mut_with_arg::*;
use std::fmt::Debug;
pub use with_arg::*;
pub use with_arg_and_return::*;
pub use with_return::*;
pub trait CloneableFn: FnOnce() {
fn clone_box(&self) -> Box<dyn CloneableFn>;
}
impl<F> CloneableFn for F
where
F: FnOnce() + Clone + 'static,
{
fn clone_box(&self) -> Box<dyn CloneableFn> {
Box::new(self.clone())
}
}
impl Clone for Box<dyn CloneableFn> {
fn clone(&self) -> Self {
(**self).clone_box()
}
}
impl Default for Box<dyn CloneableFn> {
fn default() -> Self {
Box::new(|| {})
}
}
impl Debug for Box<dyn CloneableFn> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Box<dyn CloneableFn>",)
}
}

View file

@ -0,0 +1,32 @@
use std::fmt::Debug;
pub trait CloneableFnMut: FnMut() {
fn clone_box(&self) -> Box<dyn CloneableFnMut>;
}
impl<F> CloneableFnMut for F
where
F: FnMut() + Clone + 'static,
{
fn clone_box(&self) -> Box<dyn CloneableFnMut> {
Box::new(self.clone())
}
}
impl Clone for Box<dyn CloneableFnMut> {
fn clone(&self) -> Self {
(**self).clone_box()
}
}
impl Default for Box<dyn CloneableFnMut> {
fn default() -> Self {
Box::new(|| {})
}
}
impl Debug for Box<dyn CloneableFnMut> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Box<dyn CloneableFnMut>",)
}
}

View file

@ -0,0 +1,36 @@
use std::fmt::Debug;
pub trait CloneableFnMutWithArg<Arg>: FnMut(Arg) {
fn clone_box(&self) -> Box<dyn CloneableFnMutWithArg<Arg>>;
}
impl<F, Arg> CloneableFnMutWithArg<Arg> for F
where
F: FnMut(Arg) + Clone + 'static,
{
fn clone_box(&self) -> Box<dyn CloneableFnMutWithArg<Arg>> {
Box::new(self.clone())
}
}
impl<Arg> Clone for Box<dyn CloneableFnMutWithArg<Arg>> {
fn clone(&self) -> Self {
(**self).clone_box()
}
}
impl<Arg> Default for Box<dyn CloneableFnMutWithArg<Arg>> {
fn default() -> Self {
Box::new(|_| {})
}
}
impl<Arg> Debug for Box<dyn CloneableFnMutWithArg<Arg>> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Box<dyn CloneableFnMutWithArg<{}>>",
std::any::type_name::<Arg>()
)
}
}

View file

@ -0,0 +1,36 @@
use std::fmt::Debug;
pub trait CloneableFnWithArg<Arg>: FnOnce(Arg) {
fn clone_box(&self) -> Box<dyn CloneableFnWithArg<Arg>>;
}
impl<F, Arg> CloneableFnWithArg<Arg> for F
where
F: FnOnce(Arg) + Clone + 'static,
{
fn clone_box(&self) -> Box<dyn CloneableFnWithArg<Arg>> {
Box::new(self.clone())
}
}
impl<Arg> Clone for Box<dyn CloneableFnWithArg<Arg>> {
fn clone(&self) -> Self {
(**self).clone_box()
}
}
impl<Arg> Default for Box<dyn CloneableFnWithArg<Arg>> {
fn default() -> Self {
Box::new(|_| {})
}
}
impl<Arg> Debug for Box<dyn CloneableFnWithArg<Arg>> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Box<dyn CloneableFnWithArg<{}>>",
std::any::type_name::<Arg>()
)
}
}

View file

@ -0,0 +1,38 @@
use std::fmt::Debug;
pub trait CloneableFnWithArgAndReturn<Arg, R>: FnOnce(Arg) -> R {
fn clone_box(&self) -> Box<dyn CloneableFnWithArgAndReturn<Arg, R>>;
}
impl<F, R, Arg> CloneableFnWithArgAndReturn<Arg, R> for F
where
F: FnMut(Arg) -> R + Clone + 'static,
R: 'static,
{
fn clone_box(&self) -> Box<dyn CloneableFnWithArgAndReturn<Arg, R>> {
Box::new(self.clone())
}
}
impl<R, Arg> Clone for Box<dyn CloneableFnWithArgAndReturn<Arg, R>> {
fn clone(&self) -> Self {
(**self).clone_box()
}
}
impl<R: Default + 'static, Arg> Default for Box<dyn CloneableFnWithArgAndReturn<Arg, R>> {
fn default() -> Self {
Box::new(|_| Default::default())
}
}
impl<R, Arg> Debug for Box<dyn CloneableFnWithArgAndReturn<Arg, R>> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Box<dyn CloneableFnWithArgAndReturn<{}, {}>>",
std::any::type_name::<Arg>(),
std::any::type_name::<R>()
)
}
}

View file

@ -0,0 +1,37 @@
use std::fmt::Debug;
pub trait CloneableFnWithReturn<R>: FnOnce() -> R {
fn clone_box(&self) -> Box<dyn CloneableFnWithReturn<R>>;
}
impl<F, R> CloneableFnWithReturn<R> for F
where
F: FnOnce() -> R + Clone + 'static,
R: 'static,
{
fn clone_box(&self) -> Box<dyn CloneableFnWithReturn<R>> {
Box::new(self.clone())
}
}
impl<R> Clone for Box<dyn CloneableFnWithReturn<R>> {
fn clone(&self) -> Self {
(**self).clone_box()
}
}
impl<R: Default + 'static> Default for Box<dyn CloneableFnWithReturn<R>> {
fn default() -> Self {
Box::new(|| Default::default())
}
}
impl<R> Debug for Box<dyn CloneableFnWithReturn<R>> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Box<dyn CloneableFnWithReturn<{}>>",
std::any::type_name::<R>()
)
}
}