From ec31031fde86bd95d550a595c08e05b7d7322bd6 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Fri, 24 Mar 2023 11:03:18 +0100 Subject: [PATCH] glib: Replace Continue with ControlFlow Fixes #1063 --- gio/src/datagram_based.rs | 12 +- gio/src/pollable_input_stream.rs | 14 +-- gio/src/pollable_output_stream.rs | 16 +-- gio/src/socket.rs | 12 +- glib/src/main_context_channel.rs | 36 +++--- glib/src/prelude.rs | 4 +- glib/src/source.rs | 198 +++++++++++++++++++----------- glib/src/source_futures.rs | 20 +-- 8 files changed, 184 insertions(+), 128 deletions(-) diff --git a/gio/src/datagram_based.rs b/gio/src/datagram_based.rs index 628b779e7685..053bc4695fb2 100644 --- a/gio/src/datagram_based.rs +++ b/gio/src/datagram_based.rs @@ -18,7 +18,7 @@ pub trait DatagramBasedExtManual: Sized { func: F, ) -> glib::Source where - F: FnMut(&Self, glib::IOCondition) -> glib::Continue + 'static, + F: FnMut(&Self, glib::IOCondition) -> glib::ControlFlow + 'static, C: IsA; fn create_source_future>( @@ -72,12 +72,12 @@ impl> DatagramBasedExtManual for O { func: F, ) -> glib::Source where - F: FnMut(&Self, glib::IOCondition) -> glib::Continue + 'static, + F: FnMut(&Self, glib::IOCondition) -> glib::ControlFlow + 'static, C: IsA, { unsafe extern "C" fn trampoline< O: IsA, - F: FnMut(&O, glib::IOCondition) -> glib::Continue + 'static, + F: FnMut(&O, glib::IOCondition) -> glib::ControlFlow + 'static, >( datagram_based: *mut ffi::GDatagramBased, condition: glib::ffi::GIOCondition, @@ -140,7 +140,7 @@ impl> DatagramBasedExtManual for O { priority, move |_, condition| { let _ = send.take().unwrap().send(condition); - glib::Continue(false) + glib::ControlFlow::Break }, ) })) @@ -164,9 +164,9 @@ impl> DatagramBasedExtManual for O { priority, move |_, condition| { if send.as_ref().unwrap().unbounded_send(condition).is_err() { - glib::Continue(false) + glib::ControlFlow::Break } else { - glib::Continue(true) + glib::ControlFlow::Continue } }, ) diff --git a/gio/src/pollable_input_stream.rs b/gio/src/pollable_input_stream.rs index 664c17bf9cd5..b19e8162933a 100644 --- a/gio/src/pollable_input_stream.rs +++ b/gio/src/pollable_input_stream.rs @@ -21,7 +21,7 @@ pub trait PollableInputStreamExtManual: Sized { func: F, ) -> glib::Source where - F: FnMut(&Self) -> glib::Continue + 'static, + F: FnMut(&Self) -> glib::ControlFlow + 'static, C: IsA; fn create_source_future>( @@ -64,12 +64,12 @@ impl> PollableInputStreamExtManual for O { func: F, ) -> glib::Source where - F: FnMut(&Self) -> glib::Continue + 'static, + F: FnMut(&Self) -> glib::ControlFlow + 'static, C: IsA, { unsafe extern "C" fn trampoline< O: IsA, - F: FnMut(&O) -> glib::Continue + 'static, + F: FnMut(&O) -> glib::ControlFlow + 'static, >( stream: *mut ffi::GPollableInputStream, func: glib::ffi::gpointer, @@ -146,7 +146,7 @@ impl> PollableInputStreamExtManual for O { let mut send = Some(send); obj.create_source(cancellable.as_ref(), None, priority, move |_| { let _ = send.take().unwrap().send(()); - glib::Continue(false) + glib::ControlFlow::Break }) })) } @@ -162,9 +162,9 @@ impl> PollableInputStreamExtManual for O { Box::pin(glib::SourceStream::new(move |send| { obj.create_source(cancellable.as_ref(), None, priority, move |_| { if send.unbounded_send(()).is_err() { - glib::Continue(false) + glib::ControlFlow::Break } else { - glib::Continue(true) + glib::ControlFlow::Continue } }) })) @@ -210,7 +210,7 @@ impl> AsyncRead for InputStreamAsyncRead { if let Some(waker) = waker.take() { waker.wake(); } - glib::Continue(false) + glib::ControlFlow::Break }, ); let main_context = glib::MainContext::ref_thread_default(); diff --git a/gio/src/pollable_output_stream.rs b/gio/src/pollable_output_stream.rs index 81a242afc564..8b1a7d54ac42 100644 --- a/gio/src/pollable_output_stream.rs +++ b/gio/src/pollable_output_stream.rs @@ -25,7 +25,7 @@ pub trait PollableOutputStreamExtManual { func: F, ) -> glib::Source where - F: FnMut(&Self) -> glib::Continue + 'static, + F: FnMut(&Self) -> glib::ControlFlow + 'static, C: IsA; fn create_source_future>( @@ -70,12 +70,12 @@ impl> PollableOutputStreamExtManual for O { func: F, ) -> glib::Source where - F: FnMut(&Self) -> glib::Continue + 'static, + F: FnMut(&Self) -> glib::ControlFlow + 'static, C: IsA, { unsafe extern "C" fn trampoline< O: IsA, - F: FnMut(&O) -> glib::Continue + 'static, + F: FnMut(&O) -> glib::ControlFlow + 'static, >( stream: *mut ffi::GPollableOutputStream, func: glib::ffi::gpointer, @@ -127,7 +127,7 @@ impl> PollableOutputStreamExtManual for O { let mut send = Some(send); obj.create_source(cancellable.as_ref(), None, priority, move |_| { let _ = send.take().unwrap().send(()); - glib::Continue(false) + glib::ControlFlow::Break }) })) } @@ -144,9 +144,9 @@ impl> PollableOutputStreamExtManual for O { let send = Some(send); obj.create_source(cancellable.as_ref(), None, priority, move |_| { if send.as_ref().unwrap().unbounded_send(()).is_err() { - glib::Continue(false) + glib::ControlFlow::Break } else { - glib::Continue(true) + glib::ControlFlow::Continue } }) })) @@ -218,7 +218,7 @@ impl> AsyncWrite for OutputStreamAsyncWrite { if let Some(waker) = waker.take() { waker.wake(); } - glib::Continue(false) + glib::ControlFlow::Break }, ); let main_context = glib::MainContext::ref_thread_default(); @@ -261,7 +261,7 @@ impl> AsyncWrite for OutputStreamAsyncWrite { if let Some(waker) = waker.take() { waker.wake(); } - glib::Continue(false) + glib::ControlFlow::Break }, ); let main_context = glib::MainContext::ref_thread_default(); diff --git a/gio/src/socket.rs b/gio/src/socket.rs index 6d77210e9fd8..d353dacdd1c6 100644 --- a/gio/src/socket.rs +++ b/gio/src/socket.rs @@ -397,7 +397,7 @@ pub trait SocketExtManual: Sized { func: F, ) -> glib::Source where - F: FnMut(&Self, glib::IOCondition) -> glib::Continue + 'static, + F: FnMut(&Self, glib::IOCondition) -> glib::ControlFlow + 'static, C: IsA; fn create_source_future>( @@ -775,12 +775,12 @@ impl> SocketExtManual for O { func: F, ) -> glib::Source where - F: FnMut(&Self, glib::IOCondition) -> glib::Continue + 'static, + F: FnMut(&Self, glib::IOCondition) -> glib::ControlFlow + 'static, C: IsA, { unsafe extern "C" fn trampoline< O: IsA, - F: FnMut(&O, glib::IOCondition) -> glib::Continue + 'static, + F: FnMut(&O, glib::IOCondition) -> glib::ControlFlow + 'static, >( socket: *mut ffi::GSocket, condition: glib::ffi::GIOCondition, @@ -843,7 +843,7 @@ impl> SocketExtManual for O { priority, move |_, condition| { let _ = send.take().unwrap().send(condition); - glib::Continue(false) + glib::ControlFlow::Break }, ) })) @@ -867,9 +867,9 @@ impl> SocketExtManual for O { priority, move |_, condition| { if send.as_ref().unwrap().unbounded_send(condition).is_err() { - glib::Continue(false) + glib::ControlFlow::Break } else { - glib::Continue(true) + glib::ControlFlow::Continue } }, ) diff --git a/glib/src/main_context_channel.rs b/glib/src/main_context_channel.rs index 9412216c3b50..23307a6b7a8f 100644 --- a/glib/src/main_context_channel.rs +++ b/glib/src/main_context_channel.rs @@ -7,7 +7,7 @@ use std::{ }; use crate::{ - thread_guard::ThreadGuard, translate::*, Continue, MainContext, Priority, Source, SourceId, + thread_guard::ThreadGuard, translate::*, ControlFlow, MainContext, Priority, Source, SourceId, }; enum ChannelSourceState { @@ -197,14 +197,14 @@ impl Channel { } #[repr(C)] -struct ChannelSource Continue + 'static> { +struct ChannelSource ControlFlow + 'static> { source: ffi::GSource, source_funcs: Box, channel: Channel, callback: ThreadGuard, } -unsafe extern "C" fn dispatch Continue + 'static>( +unsafe extern "C" fn dispatch ControlFlow + 'static>( source: *mut ffi::GSource, callback: ffi::GSourceFunc, _user_data: ffi::gpointer, @@ -228,7 +228,7 @@ unsafe extern "C" fn dispatch Continue + 'static>( Err(mpsc::TryRecvError::Empty) => break, Err(mpsc::TryRecvError::Disconnected) => return ffi::G_SOURCE_REMOVE, Ok(item) => { - if callback(item) == Continue(false) { + if callback(item).is_break() { return ffi::G_SOURCE_REMOVE; } } @@ -239,7 +239,7 @@ unsafe extern "C" fn dispatch Continue + 'static>( } #[cfg(feature = "v2_64")] -unsafe extern "C" fn dispose Continue + 'static>(source: *mut ffi::GSource) { +unsafe extern "C" fn dispose ControlFlow + 'static>(source: *mut ffi::GSource) { let source = &mut *(source as *mut ChannelSource); // Set the source inside the channel to None so that all senders know that there @@ -251,7 +251,7 @@ unsafe extern "C" fn dispose Continue + 'static>(source: *mut } } -unsafe extern "C" fn finalize Continue + 'static>(source: *mut ffi::GSource) { +unsafe extern "C" fn finalize ControlFlow + 'static>(source: *mut ffi::GSource) { let source = &mut *(source as *mut ChannelSource); // Drop all memory we own by taking it out of the Options @@ -453,7 +453,7 @@ impl Receiver { /// /// This function panics if called from a thread that is not the owner of the provided /// `context`, or, if `None` is provided, of the thread default main context. - pub fn attach Continue + 'static>( + pub fn attach ControlFlow + 'static>( mut self, context: Option<&MainContext>, func: F, @@ -599,9 +599,9 @@ mod tests { *sum_clone.borrow_mut() += item; if *sum_clone.borrow() == 6 { l_clone.quit(); - Continue(false) + ControlFlow::Break } else { - Continue(true) + ControlFlow::Continue } }); @@ -633,7 +633,7 @@ mod tests { let helper = Helper(l.clone()); receiver.attach(Some(&c), move |_| { let _helper = &helper; - Continue(true) + ControlFlow::Continue }); drop(sender); @@ -657,7 +657,7 @@ mod tests { let (sender, receiver) = MainContext::channel::(Priority::default()); - let source_id = receiver.attach(Some(&c), move |_| Continue(true)); + let source_id = receiver.attach(Some(&c), move |_| ControlFlow::Continue); let source = c.find_source_by_id(&source_id).unwrap(); source.destroy(); @@ -684,7 +684,7 @@ mod tests { let helper = Helper(dropped.clone()); let source_id = receiver.attach(Some(&c), move |_| { let _helper = &helper; - Continue(true) + ControlFlow::Continue }); let source = c.find_source_by_id(&source_id).unwrap(); @@ -713,9 +713,9 @@ mod tests { *sum_clone.borrow_mut() += item; if *sum_clone.borrow() == 6 { l_clone.quit(); - Continue(false) + ControlFlow::Break } else { - Continue(true) + ControlFlow::Continue } }); @@ -762,9 +762,9 @@ mod tests { *sum_clone.borrow_mut() += item; if *sum_clone.borrow() == 6 { l_clone.quit(); - Continue(false) + ControlFlow::Break } else { - Continue(true) + ControlFlow::Continue } }); @@ -873,7 +873,7 @@ mod tests { Err(mpsc::RecvTimeoutError::Disconnected) ); l_clone.quit(); - Continue(false) + ControlFlow::Break } else { // But as we didn't consume the next one yet, there must be no // other item available yet @@ -881,7 +881,7 @@ mod tests { wait_receiver.recv_timeout(time::Duration::from_millis(50)), Err(mpsc::RecvTimeoutError::Timeout) ); - Continue(true) + ControlFlow::Continue } }); l.run(); diff --git a/glib/src/prelude.rs b/glib/src/prelude.rs index f1972e164bbc..596442b2f40d 100644 --- a/glib/src/prelude.rs +++ b/glib/src/prelude.rs @@ -4,6 +4,6 @@ //! Traits and essential types intended for blanket imports. pub use crate::{ - param_spec::ParamSpecBuilderExt, Cast, CastNone, Continue, IsA, ObjectExt, ObjectType, - ParamSpecType, StaticType, StaticTypeExt, StaticVariantType, ToSendValue, ToValue, ToVariant, + param_spec::ParamSpecBuilderExt, Cast, CastNone, IsA, ObjectExt, ObjectType, ParamSpecType, + StaticType, StaticTypeExt, StaticVariantType, ToSendValue, ToValue, ToVariant, }; diff --git a/glib/src/source.rs b/glib/src/source.rs index c50f2d919fe5..916a60fe1181 100644 --- a/glib/src/source.rs +++ b/glib/src/source.rs @@ -84,50 +84,104 @@ impl FromGlib for Pid { /// /// This is the return type of `idle_add` and `timeout_add` closures. /// -/// `Continue(true)` keeps the closure assigned, to be rerun when appropriate. +/// `ControlFlow::Continue` keeps the closure assigned, to be rerun when appropriate. /// -/// `Continue(false)` disconnects and drops it. +/// `ControlFlow::Break` disconnects and drops it. #[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub struct Continue(pub bool); +pub enum ControlFlow { + Continue, + Break, +} + +impl ControlFlow { + // rustdoc-stripper-ignore-next + /// Returns `true` if this is a `Continue` variant. + pub fn is_continue(&self) -> bool { + matches!(self, Self::Continue) + } + + // rustdoc-stripper-ignore-next + /// Returns `true` if this is a `Break` variant. + pub fn is_break(&self) -> bool { + matches!(self, Self::Break) + } +} + +impl From> for ControlFlow { + fn from(c: std::ops::ControlFlow<()>) -> Self { + match c { + std::ops::ControlFlow::Break(_) => Self::Break, + std::ops::ControlFlow::Continue(_) => Self::Continue, + } + } +} + +impl From for std::ops::ControlFlow<()> { + fn from(c: ControlFlow) -> Self { + match c { + ControlFlow::Break => Self::Break(()), + ControlFlow::Continue => Self::Continue(()), + } + } +} + +impl From for ControlFlow { + fn from(c: bool) -> Self { + if c { + Self::Continue + } else { + Self::Break + } + } +} + +impl From for bool { + fn from(c: ControlFlow) -> Self { + match c { + ControlFlow::Break => false, + ControlFlow::Continue => true, + } + } +} #[doc(hidden)] -impl IntoGlib for Continue { +impl IntoGlib for ControlFlow { type GlibType = gboolean; #[inline] fn into_glib(self) -> gboolean { - self.0.into_glib() + bool::from(self).into_glib() } } -unsafe extern "C" fn trampoline Continue + Send + 'static>( +unsafe extern "C" fn trampoline ControlFlow + Send + 'static>( func: gpointer, ) -> gboolean { let func: &RefCell = &*(func as *const RefCell); (*func.borrow_mut())().into_glib() } -unsafe extern "C" fn trampoline_local Continue + 'static>( +unsafe extern "C" fn trampoline_local ControlFlow + 'static>( func: gpointer, ) -> gboolean { let func: &ThreadGuard> = &*(func as *const ThreadGuard>); (*func.get_ref().borrow_mut())().into_glib() } -unsafe extern "C" fn destroy_closure Continue + Send + 'static>(ptr: gpointer) { +unsafe extern "C" fn destroy_closure ControlFlow + Send + 'static>(ptr: gpointer) { let _ = Box::>::from_raw(ptr as *mut _); } -unsafe extern "C" fn destroy_closure_local Continue + 'static>(ptr: gpointer) { +unsafe extern "C" fn destroy_closure_local ControlFlow + 'static>(ptr: gpointer) { let _ = Box::>>::from_raw(ptr as *mut _); } -fn into_raw Continue + Send + 'static>(func: F) -> gpointer { +fn into_raw ControlFlow + Send + 'static>(func: F) -> gpointer { let func: Box> = Box::new(RefCell::new(func)); Box::into_raw(func) as gpointer } -fn into_raw_local Continue + 'static>(func: F) -> gpointer { +fn into_raw_local ControlFlow + 'static>(func: F) -> gpointer { let func: Box>> = Box::new(ThreadGuard::new(RefCell::new(func))); Box::into_raw(func) as gpointer } @@ -175,7 +229,7 @@ fn into_raw_child_watch_local(func: F) -> gpointer #[cfg(any(unix, feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(unix)))] unsafe extern "C" fn trampoline_unix_fd< - F: FnMut(RawFd, IOCondition) -> Continue + Send + 'static, + F: FnMut(RawFd, IOCondition) -> ControlFlow + Send + 'static, >( fd: i32, condition: ffi::GIOCondition, @@ -188,7 +242,7 @@ unsafe extern "C" fn trampoline_unix_fd< #[cfg(any(unix, feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(unix)))] unsafe extern "C" fn trampoline_unix_fd_local< - F: FnMut(RawFd, IOCondition) -> Continue + 'static, + F: FnMut(RawFd, IOCondition) -> ControlFlow + 'static, >( fd: i32, condition: ffi::GIOCondition, @@ -201,7 +255,7 @@ unsafe extern "C" fn trampoline_unix_fd_local< #[cfg(any(unix, feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(unix)))] unsafe extern "C" fn destroy_closure_unix_fd< - F: FnMut(RawFd, IOCondition) -> Continue + Send + 'static, + F: FnMut(RawFd, IOCondition) -> ControlFlow + Send + 'static, >( ptr: gpointer, ) { @@ -211,7 +265,7 @@ unsafe extern "C" fn destroy_closure_unix_fd< #[cfg(any(unix, feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(unix)))] unsafe extern "C" fn destroy_closure_unix_fd_local< - F: FnMut(RawFd, IOCondition) -> Continue + 'static, + F: FnMut(RawFd, IOCondition) -> ControlFlow + 'static, >( ptr: gpointer, ) { @@ -220,7 +274,7 @@ unsafe extern "C" fn destroy_closure_unix_fd_local< #[cfg(any(unix, feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(unix)))] -fn into_raw_unix_fd Continue + Send + 'static>( +fn into_raw_unix_fd ControlFlow + Send + 'static>( func: F, ) -> gpointer { let func: Box> = Box::new(RefCell::new(func)); @@ -229,7 +283,9 @@ fn into_raw_unix_fd Continue + Send + 'static>( #[cfg(any(unix, feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(unix)))] -fn into_raw_unix_fd_local Continue + 'static>(func: F) -> gpointer { +fn into_raw_unix_fd_local ControlFlow + 'static>( + func: F, +) -> gpointer { let func: Box>> = Box::new(ThreadGuard::new(RefCell::new(func))); Box::into_raw(func) as gpointer } @@ -237,26 +293,26 @@ fn into_raw_unix_fd_local Continue + 'static>(fu // rustdoc-stripper-ignore-next /// Transform a generic FnOnce into a closure that can be used as callback in various glib methods /// -/// The resulting function can only be called once and will panic otherwise. It will return `Continue(false)` +/// The resulting function can only be called once and will panic otherwise. It will return `ControlFlow::Break` /// in order to prevent being called twice. #[inline(always)] fn fnmut_callback_wrapper( func: impl FnOnce() + Send + 'static, -) -> impl FnMut() -> Continue + Send + 'static { +) -> impl FnMut() -> ControlFlow + Send + 'static { let mut func = Some(func); move || { let func = func .take() - .expect("GSource closure called after returning glib::Continue(false)"); + .expect("GSource closure called after returning ControlFlow::Break"); func(); - Continue(false) + ControlFlow::Break } } // rustdoc-stripper-ignore-next /// Transform a generic FnOnce into a closure that can be used as callback in various glib methods /// -/// The resulting function can only be called once and will panic otherwise. It will return `Continue(false)` +/// The resulting function can only be called once and will panic otherwise. It will return `ControlFlow::Break` /// in order to prevent being called twice. /// /// Different to `fnmut_callback_wrapper()`, this does not require `func` to be @@ -264,28 +320,28 @@ fn fnmut_callback_wrapper( #[inline(always)] fn fnmut_callback_wrapper_local( func: impl FnOnce() + 'static, -) -> impl FnMut() -> Continue + 'static { +) -> impl FnMut() -> ControlFlow + 'static { let mut func = Some(func); move || { let func = func .take() - .expect("GSource closure called after returning glib::Continue(false)"); + .expect("GSource closure called after returning glib::ControlFlow::Break"); func(); - Continue(false) + ControlFlow::Break } } // rustdoc-stripper-ignore-next /// Adds a closure to be called by the default main loop when it's idle. /// -/// `func` will be called repeatedly until it returns `Continue(false)`. +/// `func` will be called repeatedly until it returns `ControlFlow::Break`. /// /// The default main loop almost always is the main loop of the main thread. /// Thus, the closure is called on the main thread. #[doc(alias = "g_idle_add_full")] pub fn idle_add(func: F) -> SourceId where - F: FnMut() -> Continue + Send + 'static, + F: FnMut() -> ControlFlow + Send + 'static, { unsafe { from_glib(ffi::g_idle_add_full( @@ -300,13 +356,13 @@ where // rustdoc-stripper-ignore-next /// Adds a closure to be called by the default main loop when it's idle. /// -/// `func` will be called repeatedly until it returns `Continue(false)`. +/// `func` will be called repeatedly until it returns `ControlFlow::Break`. /// /// The default main loop almost always is the main loop of the main thread. /// Thus, the closure is called on the main thread. /// /// In comparison to `idle_add()`, this only requires `func` to be -/// `FnOnce`, and will automatically return `Continue(false)`. +/// `FnOnce`, and will automatically return `ControlFlow::Break`. #[doc(alias = "g_idle_add_full")] #[doc(alias = "g_idle_add_once")] pub fn idle_add_once(func: F) -> SourceId @@ -319,7 +375,7 @@ where // rustdoc-stripper-ignore-next /// Adds a closure to be called by the default main loop when it's idle. /// -/// `func` will be called repeatedly until it returns `Continue(false)`. +/// `func` will be called repeatedly until it returns `ControlFlow::Break`. /// /// The default main loop almost always is the main loop of the main thread. /// Thus, the closure is called on the main thread. @@ -332,7 +388,7 @@ where #[doc(alias = "g_idle_add_full")] pub fn idle_add_local(func: F) -> SourceId where - F: FnMut() -> Continue + 'static, + F: FnMut() -> ControlFlow + 'static, { unsafe { let context = MainContext::default(); @@ -351,7 +407,7 @@ where // rustdoc-stripper-ignore-next /// Adds a closure to be called by the default main loop when it's idle. /// -/// `func` will be called repeatedly until it returns `Continue(false)`. +/// `func` will be called repeatedly until it returns `ControlFlow::Break`. /// /// The default main loop almost always is the main loop of the main thread. /// Thus, the closure is called on the main thread. @@ -363,7 +419,7 @@ where /// owns the main context. /// /// In comparison to `idle_add_local()`, this only requires `func` to be -/// `FnOnce`, and will automatically return `Continue(false)`. +/// `FnOnce`, and will automatically return `ControlFlow::Break`. #[doc(alias = "g_idle_add_full")] pub fn idle_add_local_once(func: F) -> SourceId where @@ -377,7 +433,7 @@ where /// with millisecond granularity. /// /// `func` will be called repeatedly every `interval` milliseconds until it -/// returns `Continue(false)`. Precise timing is not guaranteed, the timeout may +/// returns `ControlFlow::Break`. Precise timing is not guaranteed, the timeout may /// be delayed by other events. Prefer `timeout_add_seconds` when millisecond /// precision is not necessary. /// @@ -386,7 +442,7 @@ where #[doc(alias = "g_timeout_add_full")] pub fn timeout_add(interval: Duration, func: F) -> SourceId where - F: FnMut() -> Continue + Send + 'static, + F: FnMut() -> ControlFlow + Send + 'static, { unsafe { from_glib(ffi::g_timeout_add_full( @@ -404,7 +460,7 @@ where /// with millisecond granularity. /// /// `func` will be called repeatedly every `interval` milliseconds until it -/// returns `Continue(false)`. Precise timing is not guaranteed, the timeout may +/// returns `ControlFlow::Break`. Precise timing is not guaranteed, the timeout may /// be delayed by other events. Prefer `timeout_add_seconds` when millisecond /// precision is not necessary. /// @@ -412,7 +468,7 @@ where /// Thus, the closure is called on the main thread. /// /// In comparison to `timeout_add()`, this only requires `func` to be -/// `FnOnce`, and will automatically return `Continue(false)`. +/// `FnOnce`, and will automatically return `ControlFlow::Break`. #[doc(alias = "g_timeout_add_full")] #[doc(alias = "g_timeout_add_once")] pub fn timeout_add_once(interval: Duration, func: F) -> SourceId @@ -427,7 +483,7 @@ where /// with millisecond granularity. /// /// `func` will be called repeatedly every `interval` milliseconds until it -/// returns `Continue(false)`. Precise timing is not guaranteed, the timeout may +/// returns `ControlFlow::Break`. Precise timing is not guaranteed, the timeout may /// be delayed by other events. Prefer `timeout_add_seconds` when millisecond /// precision is not necessary. /// @@ -442,7 +498,7 @@ where #[doc(alias = "g_timeout_add_full")] pub fn timeout_add_local(interval: Duration, func: F) -> SourceId where - F: FnMut() -> Continue + 'static, + F: FnMut() -> ControlFlow + 'static, { unsafe { let context = MainContext::default(); @@ -464,7 +520,7 @@ where /// with millisecond granularity. /// /// `func` will be called repeatedly every `interval` milliseconds until it -/// returns `Continue(false)`. Precise timing is not guaranteed, the timeout may +/// returns `ControlFlow::Break`. Precise timing is not guaranteed, the timeout may /// be delayed by other events. Prefer `timeout_add_seconds` when millisecond /// precision is not necessary. /// @@ -478,7 +534,7 @@ where /// owns the main context. /// /// In comparison to `timeout_add_local()`, this only requires `func` to be -/// `FnOnce`, and will automatically return `Continue(false)`. +/// `FnOnce`, and will automatically return `ControlFlow::Break`. #[doc(alias = "g_timeout_add_full")] pub fn timeout_add_local_once(interval: Duration, func: F) -> SourceId where @@ -492,7 +548,7 @@ where /// with second granularity. /// /// `func` will be called repeatedly every `interval` seconds until it -/// returns `Continue(false)`. Precise timing is not guaranteed, the timeout may +/// returns `ControlFlow::Break`. Precise timing is not guaranteed, the timeout may /// be delayed by other events. /// /// The default main loop almost always is the main loop of the main thread. @@ -500,7 +556,7 @@ where #[doc(alias = "g_timeout_add_seconds_full")] pub fn timeout_add_seconds(interval: u32, func: F) -> SourceId where - F: FnMut() -> Continue + Send + 'static, + F: FnMut() -> ControlFlow + Send + 'static, { unsafe { from_glib(ffi::g_timeout_add_seconds_full( @@ -518,14 +574,14 @@ where /// with second granularity. /// /// `func` will be called repeatedly every `interval` seconds until it -/// returns `Continue(false)`. Precise timing is not guaranteed, the timeout may +/// returns `ControlFlow::Break`. Precise timing is not guaranteed, the timeout may /// be delayed by other events. /// /// The default main loop almost always is the main loop of the main thread. /// Thus, the closure is called on the main thread. /// /// In comparison to `timeout_add_seconds()`, this only requires `func` to be -/// `FnOnce`, and will automatically return `Continue(false)`. +/// `FnOnce`, and will automatically return `ControlFlow::Break`. #[doc(alias = "g_timeout_add_seconds_full")] pub fn timeout_add_seconds_once(interval: u32, func: F) -> SourceId where @@ -539,7 +595,7 @@ where /// with second granularity. /// /// `func` will be called repeatedly every `interval` seconds until it -/// returns `Continue(false)`. Precise timing is not guaranteed, the timeout may +/// returns `ControlFlow::Break`. Precise timing is not guaranteed, the timeout may /// be delayed by other events. /// /// The default main loop almost always is the main loop of the main thread. @@ -553,7 +609,7 @@ where #[doc(alias = "g_timeout_add_seconds_full")] pub fn timeout_add_seconds_local(interval: u32, func: F) -> SourceId where - F: FnMut() -> Continue + 'static, + F: FnMut() -> ControlFlow + 'static, { unsafe { let context = MainContext::default(); @@ -575,7 +631,7 @@ where /// with second granularity. /// /// `func` will be called repeatedly every `interval` seconds until it -/// returns `Continue(false)`. Precise timing is not guaranteed, the timeout may +/// returns `ControlFlow::Break`. Precise timing is not guaranteed, the timeout may /// be delayed by other events. /// /// The default main loop almost always is the main loop of the main thread. @@ -588,7 +644,7 @@ where /// owns the main context. /// /// In comparison to `timeout_add_seconds_local()`, this only requires `func` to be -/// `FnOnce`, and will automatically return `Continue(false)`. +/// `FnOnce`, and will automatically return `ControlFlow::Break`. #[doc(alias = "g_timeout_add_seconds_full")] pub fn timeout_add_seconds_local_once(interval: u32, func: F) -> SourceId where @@ -655,14 +711,14 @@ where /// Adds a closure to be called by the default main loop whenever a UNIX signal is raised. /// /// `func` will be called repeatedly every time `signum` is raised until it -/// returns `Continue(false)`. +/// returns `ControlFlow::Break`. /// /// The default main loop almost always is the main loop of the main thread. /// Thus, the closure is called on the main thread. #[doc(alias = "g_unix_signal_add_full")] pub fn unix_signal_add(signum: i32, func: F) -> SourceId where - F: FnMut() -> Continue + Send + 'static, + F: FnMut() -> ControlFlow + Send + 'static, { unsafe { from_glib(ffi::g_unix_signal_add_full( @@ -681,13 +737,13 @@ where /// Adds a closure to be called by the default main loop whenever a UNIX signal is raised. /// /// `func` will be called repeatedly every time `signum` is raised until it -/// returns `Continue(false)`. +/// returns `ControlFlow::Break`. /// /// The default main loop almost always is the main loop of the main thread. /// Thus, the closure is called on the main thread. /// /// In comparison to `unix_signal_add()`, this only requires `func` to be -/// `FnOnce`, and will automatically return `Continue(false)`. +/// `FnOnce`, and will automatically return `ControlFlow::Break`. #[doc(alias = "g_unix_signal_add_full")] pub fn unix_signal_add_once(signum: i32, func: F) -> SourceId where @@ -702,7 +758,7 @@ where /// Adds a closure to be called by the default main loop whenever a UNIX signal is raised. /// /// `func` will be called repeatedly every time `signum` is raised until it -/// returns `Continue(false)`. +/// returns `ControlFlow::Break`. /// /// The default main loop almost always is the main loop of the main thread. /// Thus, the closure is called on the main thread. @@ -715,7 +771,7 @@ where #[doc(alias = "g_unix_signal_add_full")] pub fn unix_signal_add_local(signum: i32, func: F) -> SourceId where - F: FnMut() -> Continue + 'static, + F: FnMut() -> ControlFlow + 'static, { unsafe { let context = MainContext::default(); @@ -738,7 +794,7 @@ where /// Adds a closure to be called by the default main loop whenever a UNIX signal is raised. /// /// `func` will be called repeatedly every time `signum` is raised until it -/// returns `Continue(false)`. +/// returns `ControlFlow::Break`. /// /// The default main loop almost always is the main loop of the main thread. /// Thus, the closure is called on the main thread. @@ -750,7 +806,7 @@ where /// owns the main context. /// /// In comparison to `unix_signal_add_local()`, this only requires `func` to be -/// `FnOnce`, and will automatically return `Continue(false)`. +/// `FnOnce`, and will automatically return `ControlFlow::Break`. #[doc(alias = "g_unix_signal_add_full")] pub fn unix_signal_add_local_once(signum: i32, func: F) -> SourceId where @@ -766,14 +822,14 @@ where /// UNIX file descriptor reaches the given IO condition. /// /// `func` will be called repeatedly while the file descriptor matches the given IO condition -/// until it returns `Continue(false)`. +/// until it returns `ControlFlow::Break`. /// /// The default main loop almost always is the main loop of the main thread. /// Thus, the closure is called on the main thread. #[doc(alias = "g_unix_fd_add_full")] pub fn unix_fd_add(fd: RawFd, condition: IOCondition, func: F) -> SourceId where - F: FnMut(RawFd, IOCondition) -> Continue + Send + 'static, + F: FnMut(RawFd, IOCondition) -> ControlFlow + Send + 'static, { unsafe { from_glib(ffi::g_unix_fd_add_full( @@ -794,7 +850,7 @@ where /// UNIX file descriptor reaches the given IO condition. /// /// `func` will be called repeatedly while the file descriptor matches the given IO condition -/// until it returns `Continue(false)`. +/// until it returns `ControlFlow::Break`. /// /// The default main loop almost always is the main loop of the main thread. /// Thus, the closure is called on the main thread. @@ -807,7 +863,7 @@ where #[doc(alias = "g_unix_fd_add_full")] pub fn unix_fd_add_local(fd: RawFd, condition: IOCondition, func: F) -> SourceId where - F: FnMut(RawFd, IOCondition) -> Continue + 'static, + F: FnMut(RawFd, IOCondition) -> ControlFlow + 'static, { unsafe { let context = MainContext::default(); @@ -876,11 +932,11 @@ impl From for Priority { // rustdoc-stripper-ignore-next /// Adds a closure to be called by the main loop the return `Source` is attached to when it's idle. /// -/// `func` will be called repeatedly until it returns `Continue(false)`. +/// `func` will be called repeatedly until it returns `ControlFlow::Break`. #[doc(alias = "g_idle_source_new")] pub fn idle_source_new(name: Option<&str>, priority: Priority, func: F) -> Source where - F: FnMut() -> Continue + Send + 'static, + F: FnMut() -> ControlFlow + Send + 'static, { unsafe { let source = ffi::g_idle_source_new(); @@ -905,7 +961,7 @@ where /// intervals with millisecond granularity. /// /// `func` will be called repeatedly every `interval` milliseconds until it -/// returns `Continue(false)`. Precise timing is not guaranteed, the timeout may +/// returns `ControlFlow::Break`. Precise timing is not guaranteed, the timeout may /// be delayed by other events. Prefer `timeout_add_seconds` when millisecond /// precision is not necessary. #[doc(alias = "g_timeout_source_new")] @@ -916,7 +972,7 @@ pub fn timeout_source_new( func: F, ) -> Source where - F: FnMut() -> Continue + Send + 'static, + F: FnMut() -> ControlFlow + Send + 'static, { unsafe { let source = ffi::g_timeout_source_new(interval.as_millis() as _); @@ -941,7 +997,7 @@ where /// intervals with second granularity. /// /// `func` will be called repeatedly every `interval` seconds until it -/// returns `Continue(false)`. Precise timing is not guaranteed, the timeout may +/// returns `ControlFlow::Break`. Precise timing is not guaranteed, the timeout may /// be delayed by other events. #[doc(alias = "g_timeout_source_new_seconds")] pub fn timeout_source_new_seconds( @@ -951,7 +1007,7 @@ pub fn timeout_source_new_seconds( func: F, ) -> Source where - F: FnMut() -> Continue + Send + 'static, + F: FnMut() -> ControlFlow + Send + 'static, { unsafe { let source = ffi::g_timeout_source_new_seconds(interval); @@ -1014,7 +1070,7 @@ where /// UNIX signal is raised. /// /// `func` will be called repeatedly every time `signum` is raised until it -/// returns `Continue(false)`. +/// returns `ControlFlow::Break`. #[doc(alias = "g_unix_signal_source_new")] pub fn unix_signal_source_new( signum: i32, @@ -1023,7 +1079,7 @@ pub fn unix_signal_source_new( func: F, ) -> Source where - F: FnMut() -> Continue + Send + 'static, + F: FnMut() -> ControlFlow + Send + 'static, { unsafe { let source = ffi::g_unix_signal_source_new(signum); @@ -1050,7 +1106,7 @@ where /// UNIX file descriptor reaches the given IO condition. /// /// `func` will be called repeatedly while the file descriptor matches the given IO condition -/// until it returns `Continue(false)`. +/// until it returns `ControlFlow::Break`. #[doc(alias = "g_unix_fd_source_new")] pub fn unix_fd_source_new( fd: RawFd, @@ -1060,7 +1116,7 @@ pub fn unix_fd_source_new( func: F, ) -> Source where - F: FnMut(RawFd, IOCondition) -> Continue + Send + 'static, + F: FnMut(RawFd, IOCondition) -> ControlFlow + Send + 'static, { unsafe { let source = ffi::g_unix_fd_source_new(fd, condition.into_glib()); diff --git a/glib/src/source_futures.rs b/glib/src/source_futures.rs index c6866a3e2e05..7360b4bb605a 100644 --- a/glib/src/source_futures.rs +++ b/glib/src/source_futures.rs @@ -10,7 +10,7 @@ use futures_core::{ task::Poll, }; -use crate::{Continue, MainContext, Priority, Source}; +use crate::{ControlFlow, MainContext, Priority, Source}; // rustdoc-stripper-ignore-next /// Represents a `Future` around a `glib::Source`. The future will @@ -134,7 +134,7 @@ pub fn timeout_future_with_priority( let mut send = Some(send); crate::timeout_source_new(value, None, priority, move || { let _ = send.take().unwrap().send(()); - Continue(false) + ControlFlow::Break }) })) } @@ -159,7 +159,7 @@ pub fn timeout_future_seconds_with_priority( let mut send = Some(send); crate::timeout_source_new_seconds(value, None, priority, move || { let _ = send.take().unwrap().send(()); - Continue(false) + ControlFlow::Break }) })) } @@ -218,7 +218,7 @@ pub fn unix_signal_future_with_priority( let mut send = Some(send); crate::unix_signal_source_new(signum, None, priority, move || { let _ = send.take().unwrap().send(()); - Continue(false) + ControlFlow::Break }) })) } @@ -345,9 +345,9 @@ pub fn interval_stream_with_priority( Box::pin(SourceStream::new(move |send| { crate::timeout_source_new(value, None, priority, move || { if send.unbounded_send(()).is_err() { - Continue(false) + ControlFlow::Break } else { - Continue(true) + ControlFlow::Continue } }) })) @@ -372,9 +372,9 @@ pub fn interval_stream_seconds_with_priority( Box::pin(SourceStream::new(move |send| { crate::timeout_source_new_seconds(value, None, priority, move || { if send.unbounded_send(()).is_err() { - Continue(false) + ControlFlow::Break } else { - Continue(true) + ControlFlow::Continue } }) })) @@ -403,9 +403,9 @@ pub fn unix_signal_stream_with_priority( Box::pin(SourceStream::new(move |send| { crate::unix_signal_source_new(signum, None, priority, move || { if send.unbounded_send(()).is_err() { - Continue(false) + ControlFlow::Break } else { - Continue(true) + ControlFlow::Continue } }) }))