diff options
author | 2024-03-23 19:23:08 +0100 | |
---|---|---|
committer | 2024-03-23 19:23:08 +0100 | |
commit | 999ad2d288a9354f045bb2e1b838014b3d302779 (patch) | |
tree | d0daaae6ce58ca8e9e34ee1fc3bd6ab6a7a9ea17 /core/src | |
parent | 2b00e8b1457b0ccbafe12db3dbd6431c2c72f275 (diff) | |
download | iced-999ad2d288a9354f045bb2e1b838014b3d302779.tar.gz iced-999ad2d288a9354f045bb2e1b838014b3d302779.tar.bz2 iced-999ad2d288a9354f045bb2e1b838014b3d302779.zip |
Try catalog theming approach with `Button`
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/closure.rs | 33 | ||||
-rw-r--r-- | core/src/lib.rs | 1 |
2 files changed, 34 insertions, 0 deletions
diff --git a/core/src/closure.rs b/core/src/closure.rs new file mode 100644 index 00000000..dc7b4fee --- /dev/null +++ b/core/src/closure.rs @@ -0,0 +1,33 @@ +//! Box closures with ease. +//! +//! These are just a bunch of types that wrap boxed closures with +//! blanket [`From`] implementations for easy conversions. +//! +//! Mainly, it allows functions to take `Into<T>` where `T` may end +//! up being a boxed closure. + +/// A boxed closure that takes `A` by reference and produces `O`. +#[allow(missing_debug_implementations)] +pub struct Unary<'a, A, O>(pub Box<dyn Fn(&A) -> O + 'a>); + +impl<'a, A, O, T> From<T> for Unary<'a, A, O> +where + T: Fn(&A) -> O + 'a, +{ + fn from(f: T) -> Self { + Self(Box::new(f)) + } +} + +/// A boxed closure that takes `A` by reference and `B` by value and produces `O`. +#[allow(missing_debug_implementations)] +pub struct Binary<'a, A, B, O>(pub Box<dyn Fn(&A, B) -> O + 'a>); + +impl<'a, A, B, O, T> From<T> for Binary<'a, A, B, O> +where + T: Fn(&A, B) -> O + 'a, +{ + fn from(f: T) -> Self { + Self(Box::new(f)) + } +} diff --git a/core/src/lib.rs b/core/src/lib.rs index d076413e..36b47d80 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -19,6 +19,7 @@ pub mod alignment; pub mod border; pub mod clipboard; +pub mod closure; pub mod event; pub mod font; pub mod gradient; |