From 4e145d7f353550271ac5bc877527bd651baf79bb Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Wed, 20 Dec 2023 11:35:19 -0800 Subject: [PATCH] Removed UnwindSafe bounds appit wasn't supposed to pass along this requirement --- CHANGELOG.md | 7 ++++ Cargo.lock | 18 +++++----- Cargo.toml | 5 ++- examples/overlays.rs | 7 +--- src/animation.rs | 9 +++-- src/styles.rs | 22 +++++------- src/tick.rs | 8 ++--- src/utils.rs | 33 +---------------- src/value.rs | 20 +++++------ src/widget.rs | 17 +++++---- src/widgets/button.rs | 3 +- src/widgets/canvas.rs | 5 +-- src/widgets/custom.rs | 84 ++++++++++++------------------------------- src/widgets/data.rs | 3 +- src/widgets/input.rs | 5 ++- src/widgets/radio.rs | 5 ++- src/widgets/select.rs | 3 +- src/widgets/slider.rs | 39 +++----------------- src/window.rs | 11 +++--- 19 files changed, 94 insertions(+), 210 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f130a7..c631309 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Breaking Changes + +- Many bounds required `UnwindSafe` due to a misunderstanding on how to handle + this trait in `appit`. All requirements for `UnwindSafe` have been removed. + ## v0.1.3 (2023-12-19) ### Added diff --git a/Cargo.lock b/Cargo.lock index 94476b2..ca35007 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -90,8 +90,7 @@ dependencies = [ [[package]] name = "appit" version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3441f2d5169d7cce48f58cc16a802b6bb6e9e3edf80712ac56c681a09b92ae0" +source = "git+https://github.com/khonsulabs/appit#36a413865b6ac93e04b8a32023397714a165304d" dependencies = [ "winit", ] @@ -1148,8 +1147,7 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" [[package]] name = "kludgine" version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ceffa62a08f8cf3e8fb71f2a49df69100f7817a005014db52339d958a79ced5" +source = "git+https://github.com/khonsulabs/kludgine#bb1a2cc237b353ebd91bef62109b9bb8e3cf32e7" dependencies = [ "ahash", "alot", @@ -1747,9 +1745,9 @@ checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pkg-config" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" [[package]] name = "png" @@ -1838,9 +1836,9 @@ dependencies = [ [[package]] name = "profiling" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1de09527cd2ea2c2d59fb6c2f8c1ab8c71709ed9d1b6d60b0e1c9fbb6fdcb33c" +checksum = "d135ede8821cf6376eb7a64148901e1690b788c11ae94dc297ae917dbc91dc0e" [[package]] name = "qoi" @@ -2131,9 +2129,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "self_cell" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e388332cd64eb80cd595a00941baf513caffae8dce9cfd0467fc9c66397dade6" +checksum = "58bf37232d3bb9a2c4e641ca2a11d83b5062066f88df7fed36c28772046d65ba" [[package]] name = "serde" diff --git a/Cargo.toml b/Cargo.toml index b433e58..3a61aa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,10 @@ tracing-output = ["dep:tracing-subscriber"] roboto-flex = [] [dependencies] -kludgine = { version = "0.6.1", features = ["app"] } +# kludgine = { version = "0.6.1", features = ["app"] } +kludgine = { git = "https://github.com/khonsulabs/kludgine", features = [ + "app", +] } alot = "0.3" interner = "0.2.1" kempt = "0.2.1" diff --git a/examples/overlays.rs b/examples/overlays.rs index 1dd1f54..1add22c 100644 --- a/examples/overlays.rs +++ b/examples/overlays.rs @@ -1,5 +1,3 @@ -use std::panic::UnwindSafe; - use gooey::widget::{MakeWidget, MakeWidgetWithTag, WidgetTag}; use gooey::widgets::container::ContainerShadow; use gooey::widgets::layers::{OverlayBuilder, OverlayLayer}; @@ -54,10 +52,7 @@ fn test_widget(overlay: &OverlayLayer, is_root: bool) -> impl MakeWidget { fn show_overlay_button( label: &str, overlay: &OverlayLayer, - direction_func: impl for<'a> Fn(OverlayBuilder<'a>) -> OverlayBuilder<'a> - + Send - + UnwindSafe - + 'static, + direction_func: impl for<'a> Fn(OverlayBuilder<'a>) -> OverlayBuilder<'a> + Send + 'static, ) -> impl MakeWidget { let overlay = overlay.clone(); label.into_button().on_click(move |()| { diff --git a/src/animation.rs b/src/animation.rs index 5352f92..dd73c02 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -42,9 +42,8 @@ pub mod easings; use std::cmp::Ordering; use std::fmt::{Debug, Display}; use std::ops::{ControlFlow, Deref, Div, DivAssign, Mul, MulAssign, Sub}; -use std::panic::{RefUnwindSafe, UnwindSafe}; use std::str::FromStr; -use std::sync::{Arc, Mutex, MutexGuard, OnceLock}; +use std::sync::{Arc, Condvar, Mutex, MutexGuard, OnceLock}; use std::thread; use std::time::{Duration, Instant}; @@ -57,11 +56,11 @@ use kludgine::Color; use crate::animation::easings::Linear; use crate::styles::{Component, RequireInvalidation}; -use crate::utils::{run_in_bg, IgnorePoison, UnwindsafeCondvar}; +use crate::utils::{run_in_bg, IgnorePoison}; use crate::value::Dynamic; static ANIMATIONS: Mutex = Mutex::new(Animating::new()); -static NEW_ANIMATIONS: UnwindsafeCondvar = UnwindsafeCondvar::new(); +static NEW_ANIMATIONS: Condvar = Condvar::new(); fn thread_state() -> MutexGuard<'static, Animating> { static THREAD: OnceLock<()> = OnceLock::new(); @@ -1358,7 +1357,7 @@ impl PartialEq for EasingFunction { } /// Performs easing for value interpolation. -pub trait Easing: Debug + Send + Sync + RefUnwindSafe + UnwindSafe + 'static { +pub trait Easing: Debug + Send + Sync + 'static { /// Eases a value ranging between zero and one. The resulting value does not /// need to be bounded between zero and one. fn ease(&self, progress: ZeroToOne) -> f32; diff --git a/src/styles.rs b/src/styles.rs index 1955af3..e8c31a2 100644 --- a/src/styles.rs +++ b/src/styles.rs @@ -8,7 +8,6 @@ use std::ops::{ Add, AddAssign, Bound, Deref, Div, Mul, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive, }; -use std::panic::{RefUnwindSafe, UnwindSafe}; use std::sync::Arc; use ahash::AHashMap; @@ -374,7 +373,7 @@ impl IntoDynamicComponentValue for DynamicComponent { impl IntoDynamicComponentValue for T where - T: ComponentDefinition + Clone + RefUnwindSafe + Send + Sync + 'static, + T: ComponentDefinition + Clone + Send + Sync + 'static, { fn into_dynamic_component(self) -> Value { Value::Constant(DynamicComponent::from(self)) @@ -383,7 +382,7 @@ where impl IntoDynamicComponentValue for Dynamic where - T: ComponentDefinition + Clone + RefUnwindSafe + Send + Sync + 'static, + T: ComponentDefinition + Clone + Send + Sync + 'static, { fn into_dynamic_component(self) -> Value { Value::Dynamic(self.map_each_into()) @@ -430,7 +429,7 @@ impl Component { /// Custom components allow storing nearly any type in the style system. pub fn custom(component: T) -> Self where - T: RequireInvalidation + RefUnwindSafe + UnwindSafe + Debug + Send + Sync + 'static, + T: RequireInvalidation + Debug + Send + Sync + 'static, { Self::Custom(CustomComponent::new(component)) } @@ -441,7 +440,6 @@ impl Component { pub fn dynamic(resolve: Func) -> Self where Func: for<'a, 'context, 'widget> Fn(&'a WidgetContext<'context, 'widget>) -> Option - + RefUnwindSafe + Send + Sync + 'static, @@ -617,7 +615,7 @@ impl RequireInvalidation for Lp { impl From> for Component where Dimension: From, - Unit: Debug + UnwindSafe + RefUnwindSafe + Send + Sync + 'static, + Unit: Debug + Send + Sync + 'static, { fn from(radii: CornerRadii) -> Self { let radii = CornerRadii { @@ -1002,7 +1000,7 @@ impl CustomComponent { /// Wraps an arbitrary value so that it can be used as a [`Component`]. pub fn new(value: T) -> Self where - T: RequireInvalidation + RefUnwindSafe + UnwindSafe + Debug + Send + Sync + 'static, + T: RequireInvalidation + Debug + Send + Sync + 'static, { Self(Arc::new(value)) } @@ -1043,13 +1041,13 @@ impl ComponentType for CustomComponent { } } -trait AnyComponent: RequireInvalidation + Send + Sync + RefUnwindSafe + UnwindSafe + Debug { +trait AnyComponent: RequireInvalidation + Send + Sync + Debug { fn as_any(&self) -> &dyn Any; } impl AnyComponent for T where - T: RequireInvalidation + RefUnwindSafe + UnwindSafe + Debug + Send + Sync + 'static, + T: RequireInvalidation + Debug + Send + Sync + 'static, { fn as_any(&self) -> &dyn Any { self @@ -2534,7 +2532,7 @@ impl PartialEq for DynamicComponent { } /// A type that resolves to a [`Component`] at runtime. -pub trait DynamicComponentResolver: RefUnwindSafe + Send + Sync + 'static { +pub trait DynamicComponentResolver: Send + Sync + 'static { /// Returns the effective component, if one should be applied. fn resolve_component(&self, context: &WidgetContext<'_, '_>) -> Option; } @@ -2544,7 +2542,6 @@ struct DynamicFunctionWrapper(F); impl DynamicComponentResolver for DynamicFunctionWrapper where T: for<'a, 'context, 'widget> Fn(&'a WidgetContext<'context, 'widget>) -> Option - + RefUnwindSafe + Send + Sync + 'static, @@ -2556,7 +2553,7 @@ where impl DynamicComponentResolver for T where - T: ComponentDefinition + Clone + RefUnwindSafe + Send + Sync + 'static, + T: ComponentDefinition + Clone + Send + Sync + 'static, { fn resolve_component(&self, context: &WidgetContext<'_, '_>) -> Option { Some(context.get(self).into_component()) @@ -2579,7 +2576,6 @@ impl DynamicComponent { pub fn new(resolve: Func) -> Self where Func: for<'a, 'context, 'widget> Fn(&'a WidgetContext<'context, 'widget>) -> Option - + RefUnwindSafe + Send + Sync + 'static, diff --git a/src/tick.rs b/src/tick.rs index 6946f4c..dd3425c 100644 --- a/src/tick.rs +++ b/src/tick.rs @@ -1,5 +1,5 @@ use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::{Arc, Mutex, MutexGuard}; +use std::sync::{Arc, Condvar, Mutex, MutexGuard}; use std::time::{Duration, Instant}; use ahash::AHashSet; @@ -10,7 +10,7 @@ use kludgine::figures::units::Px; use kludgine::figures::Point; use crate::context::WidgetContext; -use crate::utils::{IgnorePoison, UnwindsafeCondvar}; +use crate::utils::IgnorePoison; use crate::value::Dynamic; use crate::widget::{EventHandling, HANDLED, IGNORED}; @@ -102,7 +102,7 @@ impl Tick { input: InputState::default(), }), period: tick_every, - sync: UnwindsafeCondvar::new(), + sync: Condvar::new(), rendered_frame: AtomicUsize::new(0), tick_number: Dynamic::default(), }); @@ -162,7 +162,7 @@ pub struct Mouse { struct TickData { state: Mutex, period: Duration, - sync: UnwindsafeCondvar, + sync: Condvar, rendered_frame: AtomicUsize, tick_number: Dynamic, } diff --git a/src/utils.rs b/src/utils.rs index 0036def..cbb9782 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,42 +1,11 @@ use std::ops::Deref; use std::sync::mpsc::{self, SyncSender}; -use std::sync::{Condvar, OnceLock, PoisonError}; +use std::sync::{OnceLock, PoisonError}; use intentional::Assert; use kludgine::app::winit::event::Modifiers; use kludgine::app::winit::keyboard::ModifiersState; -/// This [`Condvar`] is a wrapper that on Mac OS/iOS/Windows asserts unwind safety. On -/// all other platforms, this is a transparent wrapper around `Condvar`. See -/// for more information. -#[derive(Debug, Default)] -pub struct UnwindsafeCondvar( - #[cfg(any(target_os = "ios", target_os = "macos", target_os = "windows"))] std::panic::AssertUnwindSafe, - #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "windows")))] Condvar, -); - -impl Deref for UnwindsafeCondvar { - type Target = Condvar; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl UnwindsafeCondvar { - pub const fn new() -> Self { - #[cfg(any(target_os = "ios", target_os = "macos", target_os = "windows"))] - { - Self(std::panic::AssertUnwindSafe(Condvar::new())) - } - - #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "windows")))] - { - Self(Condvar::new()) - } - } -} - /// Invokes the provided macro with a pattern that can be matched using this /// `macro_rules!` expression: `$($type:ident $field:tt $var:ident),+`, where `$type` is an /// identifier to use for the generic parameter and `$field` is the field index diff --git a/src/value.rs b/src/value.rs index 9ee0a0e..5abd4a8 100644 --- a/src/value.rs +++ b/src/value.rs @@ -5,9 +5,8 @@ use std::fmt::{self, Debug, Display}; use std::future::Future; use std::hash::{BuildHasher, Hash}; use std::ops::{Deref, DerefMut, Not}; -use std::panic::UnwindSafe; use std::str::FromStr; -use std::sync::{Arc, Mutex, MutexGuard, TryLockError, Weak}; +use std::sync::{Arc, Condvar, Mutex, MutexGuard, TryLockError, Weak}; use std::task::{Poll, Waker}; use std::thread::{self, ThreadId}; use std::time::{Duration, Instant}; @@ -20,7 +19,7 @@ use kempt::{Map, Sort}; use crate::animation::{AnimationHandle, DynamicTransition, IntoAnimate, LinearInterpolate, Spawn}; use crate::context::sealed::WindowHandle; use crate::context::{self, WidgetContext}; -use crate::utils::{run_in_bg, IgnorePoison, UnwindsafeCondvar, WithClone}; +use crate::utils::{run_in_bg, IgnorePoison, WithClone}; use crate::widget::{Children, MakeWidget, MakeWidgetWithTag, WidgetId, WidgetInstance}; use crate::widgets::{Radio, Select, Space, Switcher}; @@ -45,7 +44,7 @@ impl Dynamic { source_callback: None, }), during_callback_state: Mutex::default(), - sync: UnwindsafeCondvar::default(), + sync: Condvar::default(), })) } @@ -759,7 +758,7 @@ struct LockState { struct DynamicData { state: Mutex>, during_callback_state: Mutex>, - sync: UnwindsafeCondvar, + sync: Condvar, } impl DynamicData { @@ -998,7 +997,7 @@ where struct ChangeCallbacksData { callbacks: Mutex, currently_executing: Mutex>, - sync: UnwindsafeCondvar, + sync: Condvar, } struct CallbacksList { @@ -2319,7 +2318,7 @@ impl Validations { fn invoke_callback(&self, t: T, handler: &mut F) -> R where - F: FnMut(T) -> R + UnwindSafe + Send + 'static, + F: FnMut(T) -> R + Send + 'static, R: Default, { let mut state = self.state.lock(); @@ -2341,12 +2340,9 @@ impl Validations { /// [`Callback`](crate::widget::Callback). /// /// When the contents are invalid, `R::default()` is returned. - pub fn when_valid( - self, - mut handler: F, - ) -> impl FnMut(T) -> R + UnwindSafe + Send + 'static + pub fn when_valid(self, mut handler: F) -> impl FnMut(T) -> R + Send + 'static where - F: FnMut(T) -> R + UnwindSafe + Send + 'static, + F: FnMut(T) -> R + Send + 'static, R: Default, { move |t: T| self.invoke_callback(t, &mut handler) diff --git a/src/widget.rs b/src/widget.rs index 0844a33..da10b4e 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -4,7 +4,6 @@ use std::any::Any; use std::clone::Clone; use std::fmt::{self, Debug}; use std::ops::{ControlFlow, Deref, DerefMut}; -use std::panic::UnwindSafe; use std::sync::atomic::{self, AtomicU64}; use std::sync::{Arc, Mutex, MutexGuard}; use std::{slice, vec}; @@ -260,7 +259,7 @@ use crate::{ConstraintLimit, Run}; /// the color system works in Gooey. /// /// [repo]: https://github.com/khonsulabs/gooey -pub trait Widget: Send + UnwindSafe + Debug + 'static { +pub trait Widget: Send + Debug + 'static { /// Redraw the contents of this widget. fn redraw(&mut self, context: &mut GraphicsContext<'_, '_, '_, '_, '_>); @@ -509,7 +508,7 @@ impl From> for WrappedLayout { } /// A [`Widget`] that contains a single child. -pub trait WrapperWidget: Debug + Send + UnwindSafe + 'static { +pub trait WrapperWidget: Debug + Send + 'static { /// Returns the child widget. fn child_mut(&mut self) -> &mut WidgetRef; @@ -1603,7 +1602,7 @@ impl Callback { /// invoked. pub fn new(function: F) -> Self where - F: FnMut(T) -> R + Send + UnwindSafe + 'static, + F: FnMut(T) -> R + Send + 'static, { Self(Box::new(function)) } @@ -1614,13 +1613,13 @@ impl Callback { } } -trait CallbackFunction: Send + UnwindSafe { +trait CallbackFunction: Send { fn invoke(&mut self, value: T) -> R; } impl CallbackFunction for F where - F: FnMut(T) -> R + Send + UnwindSafe, + F: FnMut(T) -> R + Send, { fn invoke(&mut self, value: T) -> R { self(value) @@ -1653,7 +1652,7 @@ impl OnceCallback { /// invoked. pub fn new(function: F) -> Self where - F: FnOnce(T) -> R + Send + UnwindSafe + 'static, + F: FnOnce(T) -> R + Send + 'static, { Self(Box::new(Some(function))) } @@ -1664,13 +1663,13 @@ impl OnceCallback { } } -trait OnceCallbackFunction: Send + UnwindSafe { +trait OnceCallbackFunction: Send { fn invoke(&mut self, value: T) -> R; } impl OnceCallbackFunction for Option where - F: FnOnce(T) -> R + Send + UnwindSafe, + F: FnOnce(T) -> R + Send, { fn invoke(&mut self, value: T) -> R { (self.take().assert("invoked once"))(value) diff --git a/src/widgets/button.rs b/src/widgets/button.rs index f9608ef..1b07dca 100644 --- a/src/widgets/button.rs +++ b/src/widgets/button.rs @@ -1,5 +1,4 @@ //! A clickable, labeled button -use std::panic::UnwindSafe; use std::time::Duration; use kludgine::app::winit::event::{DeviceId, ElementState, KeyEvent, MouseButton}; @@ -158,7 +157,7 @@ impl Button { #[must_use] pub fn on_click(mut self, callback: F) -> Self where - F: FnMut(()) + Send + UnwindSafe + 'static, + F: FnMut(()) + Send + 'static, { self.on_click = Some(Callback::new(callback)); self diff --git a/src/widgets/canvas.rs b/src/widgets/canvas.rs index 9e78e62..11f3d88 100644 --- a/src/widgets/canvas.rs +++ b/src/widgets/canvas.rs @@ -1,5 +1,4 @@ use std::fmt::Debug; -use std::panic::UnwindSafe; use kludgine::figures::units::UPx; use kludgine::figures::Size; @@ -24,7 +23,6 @@ impl Canvas { F: for<'clip, 'gfx, 'pass, 'context, 'window> FnMut( &mut GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>, ) + Send - + UnwindSafe + 'static, { Self { @@ -65,7 +63,7 @@ impl Debug for Canvas { } } -trait RenderFunction: Send + UnwindSafe + 'static { +trait RenderFunction: Send + 'static { fn render(&mut self, context: &mut GraphicsContext<'_, '_, '_, '_, '_>); } @@ -74,7 +72,6 @@ where F: for<'clip, 'gfx, 'pass, 'context, 'window> FnMut( &mut GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>, ) + Send - + UnwindSafe + 'static, { fn render(&mut self, context: &mut GraphicsContext<'_, '_, '_, '_, '_>) { diff --git a/src/widgets/custom.rs b/src/widgets/custom.rs index d7966f1..82753e7 100644 --- a/src/widgets/custom.rs +++ b/src/widgets/custom.rs @@ -1,5 +1,4 @@ use std::fmt::Debug; -use std::panic::UnwindSafe; use kludgine::app::winit::event::{ DeviceId, Ime, KeyEvent, MouseButton, MouseScrollDelta, TouchPhase, @@ -121,7 +120,6 @@ impl Custom { pub fn on_redraw(mut self, redraw: Redraw) -> Self where Redraw: Send - + UnwindSafe + 'static + for<'context, 'window, 'clip, 'gfx, 'pass> FnMut( &mut GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>, @@ -144,7 +142,6 @@ impl Custom { pub fn on_redraw_after_child(mut self, redraw: Redraw) -> Self where Redraw: Send - + UnwindSafe + 'static + for<'context, 'window, 'clip, 'gfx, 'pass> FnMut( &mut GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>, @@ -159,10 +156,8 @@ impl Custom { /// This callback corresponds to [`WrapperWidget::mounted`]. pub fn on_mounted(mut self, mounted: Mounted) -> Self where - Mounted: Send - + UnwindSafe - + 'static - + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>), + Mounted: + Send + 'static + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>), { self.mounted = Some(Box::new(mounted)); self @@ -174,10 +169,8 @@ impl Custom { /// This callback corresponds to [`WrapperWidget::unmounted`]. pub fn on_unmounted(mut self, mounted: Mounted) -> Self where - Mounted: Send - + UnwindSafe - + 'static - + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>), + Mounted: + Send + 'static + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>), { self.unmounted = Some(Box::new(mounted)); self @@ -188,10 +181,8 @@ impl Custom { /// This callback corresponds to [`WrapperWidget::unhover`]. pub fn on_unhover(mut self, unhovered: Unhover) -> Self where - Unhover: Send - + UnwindSafe - + 'static - + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>), + Unhover: + Send + 'static + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>), { self.unhover = Some(Box::new(unhovered)); self @@ -202,10 +193,8 @@ impl Custom { /// This callback corresponds to [`WrapperWidget::focus`]. pub fn on_focus(mut self, focus: Focused) -> Self where - Focused: Send - + UnwindSafe - + 'static - + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>), + Focused: + Send + 'static + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>), { self.focus = Some(Box::new(focus)); self @@ -216,10 +205,7 @@ impl Custom { /// This callback corresponds to [`WrapperWidget::blur`]. pub fn on_blur(mut self, blur: Blur) -> Self where - Blur: Send - + UnwindSafe - + 'static - + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>), + Blur: Send + 'static + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>), { self.blur = Some(Box::new(blur)); self @@ -230,10 +216,8 @@ impl Custom { /// This callback corresponds to [`WrapperWidget::activate`]. pub fn on_activate(mut self, activated: Activated) -> Self where - Activated: Send - + UnwindSafe - + 'static - + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>), + Activated: + Send + 'static + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>), { self.activate = Some(Box::new(activated)); self @@ -244,10 +228,8 @@ impl Custom { /// This callback corresponds to [`WrapperWidget::deactivate`]. pub fn on_deactivate(mut self, deactivated: Deactivated) -> Self where - Deactivated: Send - + UnwindSafe - + 'static - + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>), + Deactivated: + Send + 'static + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>), { self.deactivate = Some(Box::new(deactivated)); self @@ -260,7 +242,6 @@ impl Custom { pub fn on_accept_focus(mut self, accept: AcceptFocus) -> Self where AcceptFocus: Send - + UnwindSafe + 'static + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>) -> bool, { @@ -276,7 +257,6 @@ impl Custom { pub fn on_allow_blur(mut self, allow_blur: AllowBlur) -> Self where AllowBlur: Send - + UnwindSafe + 'static + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>) -> bool, { @@ -293,7 +273,6 @@ impl Custom { pub fn on_advance_focus(mut self, advance_focus: AdvanceFocus) -> Self where AdvanceFocus: Send - + UnwindSafe + 'static + for<'context, 'window> FnMut( VisualOrder, @@ -315,7 +294,6 @@ impl Custom { ) -> Self where AdjustChildConstraints: Send - + UnwindSafe + 'static + for<'context, 'window, 'clip, 'gfx, 'pass> FnMut( Size, @@ -332,7 +310,6 @@ impl Custom { pub fn on_position_child(mut self, position_child: PositionChild) -> Self where PositionChild: Send - + UnwindSafe + 'static + for<'context, 'window, 'clip, 'gfx, 'pass> FnMut( Size, @@ -351,7 +328,6 @@ impl Custom { pub fn on_hit_test(mut self, hit_test: HitTest) -> Self where HitTest: Send - + UnwindSafe + 'static + for<'context, 'window> FnMut(Point, &mut EventContext<'context, 'window>) -> bool, { @@ -365,7 +341,6 @@ impl Custom { pub fn on_hover(mut self, hover: Hover) -> Self where Hover: Send - + UnwindSafe + 'static + for<'context, 'window> FnMut( Point, @@ -388,7 +363,6 @@ impl Custom { pub fn on_mouse_down(mut self, mouse_down: MouseDown) -> Self where MouseDown: Send - + UnwindSafe + 'static + for<'context, 'window> FnMut( Point, @@ -408,7 +382,6 @@ impl Custom { pub fn on_mouse_drag(mut self, mouse_drag: MouseDrag) -> Self where MouseDrag: Send - + UnwindSafe + 'static + for<'context, 'window> FnMut( Point, @@ -427,7 +400,6 @@ impl Custom { pub fn on_mouse_up(mut self, mouse_up: MouseUp) -> Self where MouseUp: Send - + UnwindSafe + 'static + for<'context, 'window> FnMut( Option>, @@ -446,7 +418,6 @@ impl Custom { pub fn on_ime(mut self, ime: OnIme) -> Self where OnIme: Send - + UnwindSafe + 'static + for<'context, 'window> FnMut(Ime, &mut EventContext<'context, 'window>) -> EventHandling, { @@ -460,7 +431,6 @@ impl Custom { pub fn on_keyboard_input(mut self, keyboard_input: KeyboardInput) -> Self where KeyboardInput: Send - + UnwindSafe + 'static + for<'context, 'window> FnMut( DeviceId, @@ -479,7 +449,6 @@ impl Custom { pub fn mouse_wheel(mut self, mouse_wheel: MouseWheel) -> Self where MouseWheel: Send - + UnwindSafe + 'static + for<'context, 'window> FnMut( DeviceId, @@ -711,14 +680,13 @@ impl WrapperWidget for Custom { } } -trait RedrawFunc: Send + UnwindSafe { +trait RedrawFunc: Send { fn invoke(&mut self, context: &mut GraphicsContext<'_, '_, '_, '_, '_>); } impl RedrawFunc for Func where Func: Send - + UnwindSafe + 'static + for<'context, 'window, 'clip, 'gfx, 'pass> FnMut( &mut GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>, @@ -729,7 +697,7 @@ where } } -trait AdjustChildConstraintsFunc: Send + UnwindSafe { +trait AdjustChildConstraintsFunc: Send { fn invoke( &mut self, available_space: Size, @@ -740,7 +708,6 @@ trait AdjustChildConstraintsFunc: Send + UnwindSafe { impl AdjustChildConstraintsFunc for Func where Func: Send - + UnwindSafe + 'static + for<'context, 'window, 'clip, 'gfx, 'pass> FnMut( Size, @@ -756,7 +723,7 @@ where } } -trait PositionChildFunc: Send + UnwindSafe { +trait PositionChildFunc: Send { fn invoke( &mut self, size: Size, @@ -768,7 +735,6 @@ trait PositionChildFunc: Send + UnwindSafe { impl PositionChildFunc for Func where Func: Send - + UnwindSafe + 'static + for<'context, 'window, 'clip, 'gfx, 'pass> FnMut( Size, @@ -786,39 +752,34 @@ where } } -trait EventFunc: Send + UnwindSafe { +trait EventFunc: Send { fn invoke(&mut self, context: &mut EventContext<'_, '_>) -> R; } impl EventFunc for Func where - Func: Send - + UnwindSafe - + 'static - + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>) -> R, + Func: Send + 'static + for<'context, 'window> FnMut(&mut EventContext<'context, 'window>) -> R, { fn invoke(&mut self, context: &mut EventContext<'_, '_>) -> R { self(context) } } -trait OneParamEventFunc: Send + UnwindSafe { +trait OneParamEventFunc: Send { fn invoke(&mut self, param: P, context: &mut EventContext<'_, '_>) -> R; } impl OneParamEventFunc for Func where - Func: Send - + UnwindSafe - + 'static - + for<'context, 'window> FnMut(P, &mut EventContext<'context, 'window>) -> R, + Func: + Send + 'static + for<'context, 'window> FnMut(P, &mut EventContext<'context, 'window>) -> R, { fn invoke(&mut self, location: P, context: &mut EventContext<'_, '_>) -> R { self(location, context) } } -trait ThreeParamEventFunc: Send + UnwindSafe { +trait ThreeParamEventFunc: Send { fn invoke( &mut self, location: P1, @@ -833,7 +794,6 @@ type MouseUpFunc = dyn ThreeParamEventFunc>, DeviceId, MouseBut impl ThreeParamEventFunc for Func where Func: Send - + UnwindSafe + 'static + for<'context, 'window> FnMut(P1, P2, P3, &mut EventContext<'context, 'window>) -> R, { diff --git a/src/widgets/data.rs b/src/widgets/data.rs index 100ff07..e1cea76 100644 --- a/src/widgets/data.rs +++ b/src/widgets/data.rs @@ -1,5 +1,4 @@ use std::fmt::Debug; -use std::panic::UnwindSafe; use crate::widget::{MakeWidget, WidgetRef, WrapperWidget}; use crate::widgets::Space; @@ -48,7 +47,7 @@ where impl WrapperWidget for Data where - T: Debug + Send + UnwindSafe + 'static, + T: Debug + Send + 'static, { fn child_mut(&mut self) -> &mut WidgetRef { &mut self.child diff --git a/src/widgets/input.rs b/src/widgets/input.rs index caff188..7443a27 100644 --- a/src/widgets/input.rs +++ b/src/widgets/input.rs @@ -5,7 +5,6 @@ use std::cmp::Ordering; use std::fmt::{self, Debug, Display, Formatter, Write}; use std::hash::Hash; use std::ops::{Deref, DerefMut}; -use std::panic::UnwindSafe; use std::sync::{Arc, OnceLock}; use std::time::Duration; @@ -163,7 +162,7 @@ where /// is returned, this widget will ignore the event. pub fn on_key(mut self, on_key: F) -> Self where - F: FnMut(KeyEvent) -> EventHandling + Send + UnwindSafe + 'static, + F: FnMut(KeyEvent) -> EventHandling + Send + 'static, { self.on_key = Some(Callback::new(on_key)); self @@ -1280,7 +1279,7 @@ impl BlinkState { /// - `Cow<'static, str>` /// - [`CowString`] /// - [`MaskedString`] -pub trait InputStorage: UnwindSafe + Send + 'static { +pub trait InputStorage: Send + 'static { /// If true, the input field should display a mask instead of the actual /// string by default. const MASKED: bool; diff --git a/src/widgets/radio.rs b/src/widgets/radio.rs index 062e3b9..cbdf2bb 100644 --- a/src/widgets/radio.rs +++ b/src/widgets/radio.rs @@ -1,6 +1,5 @@ //! A labeled widget with a circular indicator representing a value. use std::fmt::Debug; -use std::panic::UnwindSafe; use kludgine::figures::units::Lp; use kludgine::figures::{Point, ScreenScale, Size}; @@ -53,7 +52,7 @@ impl Radio { impl MakeWidgetWithTag for Radio where - T: Clone + Debug + Eq + UnwindSafe + Send + 'static, + T: Clone + Debug + Eq + Send + 'static, { fn make_with_tag(self, id: crate::widget::WidgetTag) -> WidgetInstance { RadioOrnament { @@ -79,7 +78,7 @@ struct RadioOrnament { impl Widget for RadioOrnament where - T: Debug + Eq + UnwindSafe + Send + 'static, + T: Debug + Eq + Send + 'static, { fn redraw(&mut self, context: &mut GraphicsContext<'_, '_, '_, '_, '_>) { let radio_size = context diff --git a/src/widgets/select.rs b/src/widgets/select.rs index ed416ff..7a53daa 100644 --- a/src/widgets/select.rs +++ b/src/widgets/select.rs @@ -1,6 +1,5 @@ //! A selectable, labeled widget representing a value. use std::fmt::Debug; -use std::panic::{RefUnwindSafe, UnwindSafe}; use kludgine::Color; @@ -48,7 +47,7 @@ impl Select { impl MakeWidgetWithTag for Select where - T: Clone + Debug + Eq + RefUnwindSafe + UnwindSafe + Send + Sync + 'static, + T: Clone + Debug + Eq + Send + Sync + 'static, { fn make_with_tag(self, id: crate::widget::WidgetTag) -> WidgetInstance { let selected = self.state.map_each({ diff --git a/src/widgets/slider.rs b/src/widgets/slider.rs index a42c207..49d0ffd 100644 --- a/src/widgets/slider.rs +++ b/src/widgets/slider.rs @@ -2,7 +2,6 @@ use std::fmt::Debug; use std::mem; use std::ops::RangeInclusive; -use std::panic::UnwindSafe; use intentional::{Assert, Cast as _}; use kludgine::app::winit::event::{DeviceId, MouseButton, MouseScrollDelta, TouchPhase}; @@ -786,16 +785,9 @@ define_components! { } /// A value that can be used in a [`Slider`] widget. -pub trait SliderValue: Clone + PartialEq + UnwindSafe + Send + Debug + 'static { +pub trait SliderValue: Clone + PartialEq + Send + Debug + 'static { /// The component value for the slider. - type Value: Clone - + Debug - + PartialOrd - + LinearInterpolate - + PercentBetween - + UnwindSafe - + Send - + 'static; + type Value: Clone + Debug + PartialOrd + LinearInterpolate + PercentBetween + Send + 'static; /// When true, this type is expected to represent two values: start and an /// end. const RANGED: bool; @@ -808,14 +800,7 @@ pub trait SliderValue: Clone + PartialEq + UnwindSafe + Send + Debug + 'static { impl SliderValue for T where - T: Clone - + Debug - + PartialOrd - + LinearInterpolate - + PercentBetween - + UnwindSafe - + Send - + 'static, + T: Clone + Debug + PartialOrd + LinearInterpolate + PercentBetween + Send + 'static, { type Value = T; @@ -832,14 +817,7 @@ where impl SliderValue for RangeInclusive where - T: Clone - + Debug - + PartialOrd - + LinearInterpolate - + PercentBetween - + UnwindSafe - + Send - + 'static, + T: Clone + Debug + PartialOrd + LinearInterpolate + PercentBetween + Send + 'static, { type Value = T; @@ -857,14 +835,7 @@ where impl SliderValue for (T, T) where - T: Clone - + Debug - + PartialOrd - + LinearInterpolate - + PercentBetween - + UnwindSafe - + Send - + 'static, + T: Clone + Debug + PartialOrd + LinearInterpolate + PercentBetween + Send + 'static, { type Value = T; diff --git a/src/window.rs b/src/window.rs index 76b539c..cbec139 100644 --- a/src/window.rs +++ b/src/window.rs @@ -3,7 +3,6 @@ use std::cell::RefCell; use std::ffi::OsStr; use std::ops::{Deref, DerefMut, Not}; -use std::panic::{AssertUnwindSafe, UnwindSafe}; use std::path::Path; use std::string::ToString; use std::sync::{MutexGuard, OnceLock}; @@ -309,7 +308,7 @@ where { fn run(self) -> crate::Result { initialize_tracing(); - GooeyWindow::::run_with(AssertUnwindSafe(sealed::Context { + GooeyWindow::::run_with(sealed::Context { user: self.context, settings: RefCell::new(sealed::WindowSettings { gooey: self.gooey, @@ -327,14 +326,14 @@ where monospace_font_family: self.monospace_font_family, cursive_font_family: self.cursive_font_family, }), - })) + }) } } /// The behavior of a Gooey window. pub trait WindowBehavior: Sized + 'static { /// The type that is provided when initializing this window. - type Context: UnwindSafe + Send + 'static; + type Context: Send + 'static; /// Return a new instance of this behavior using `context`. fn initialize(window: &mut RunningWindow<'_>, context: Self::Context) -> Self; @@ -568,12 +567,12 @@ impl kludgine::app::WindowBehavior for GooeyWindow where T: WindowBehavior, { - type Context = AssertUnwindSafe>; + type Context = sealed::Context; fn initialize( window: kludgine::app::Window<'_, WindowCommand>, graphics: &mut kludgine::Graphics<'_>, - AssertUnwindSafe(context): Self::Context, + context: Self::Context, ) -> Self { let mut settings = context.settings.borrow_mut(); let gooey = settings.gooey.clone();