Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glib: Replace Continue with ControlFlow #1066

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions gio/src/datagram_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ pub trait DatagramBasedExtManual: sealed::Sealed + IsA<DatagramBased> + Sized {
func: F,
) -> glib::Source
where
F: FnMut(&Self, glib::IOCondition) -> glib::Continue + 'static,
F: FnMut(&Self, glib::IOCondition) -> glib::ControlFlow + 'static,
C: IsA<Cancellable>,
{
unsafe extern "C" fn trampoline<
O: IsA<DatagramBased>,
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,
Expand Down Expand Up @@ -91,7 +91,7 @@ pub trait DatagramBasedExtManual: sealed::Sealed + IsA<DatagramBased> + Sized {
priority,
move |_, condition| {
let _ = send.take().unwrap().send(condition);
glib::Continue(false)
glib::ControlFlow::Break
},
)
}))
Expand All @@ -115,9 +115,9 @@ pub trait DatagramBasedExtManual: sealed::Sealed + IsA<DatagramBased> + Sized {
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
}
},
)
Expand Down
12 changes: 6 additions & 6 deletions gio/src/pollable_input_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ pub trait PollableInputStreamExtManual: sealed::Sealed + IsA<PollableInputStream
func: F,
) -> glib::Source
where
F: FnMut(&Self) -> glib::Continue + 'static,
F: FnMut(&Self) -> glib::ControlFlow + 'static,
C: IsA<Cancellable>,
{
unsafe extern "C" fn trampoline<
O: IsA<PollableInputStream>,
F: FnMut(&O) -> glib::Continue + 'static,
F: FnMut(&O) -> glib::ControlFlow + 'static,
>(
stream: *mut ffi::GPollableInputStream,
func: glib::ffi::gpointer,
Expand Down Expand Up @@ -83,7 +83,7 @@ pub trait PollableInputStreamExtManual: sealed::Sealed + IsA<PollableInputStream
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
})
}))
}
Expand All @@ -99,9 +99,9 @@ pub trait PollableInputStreamExtManual: sealed::Sealed + IsA<PollableInputStream
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
}
})
}))
Expand Down Expand Up @@ -186,7 +186,7 @@ impl<T: IsA<PollableInputStream>> AsyncRead for InputStreamAsyncRead<T> {
if let Some(waker) = waker.take() {
waker.wake();
}
glib::Continue(false)
glib::ControlFlow::Break
},
);
let main_context = glib::MainContext::ref_thread_default();
Expand Down
14 changes: 7 additions & 7 deletions gio/src/pollable_output_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ pub trait PollableOutputStreamExtManual: sealed::Sealed + IsA<PollableOutputStre
func: F,
) -> glib::Source
where
F: FnMut(&Self) -> glib::Continue + 'static,
F: FnMut(&Self) -> glib::ControlFlow + 'static,
C: IsA<Cancellable>,
{
unsafe extern "C" fn trampoline<
O: IsA<PollableOutputStream>,
F: FnMut(&O) -> glib::Continue + 'static,
F: FnMut(&O) -> glib::ControlFlow + 'static,
>(
stream: *mut ffi::GPollableOutputStream,
func: glib::ffi::gpointer,
Expand Down Expand Up @@ -87,7 +87,7 @@ pub trait PollableOutputStreamExtManual: sealed::Sealed + IsA<PollableOutputStre
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
})
}))
}
Expand All @@ -104,9 +104,9 @@ pub trait PollableOutputStreamExtManual: sealed::Sealed + IsA<PollableOutputStre
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
}
})
}))
Expand Down Expand Up @@ -192,7 +192,7 @@ impl<T: IsA<PollableOutputStream>> AsyncWrite for OutputStreamAsyncWrite<T> {
if let Some(waker) = waker.take() {
waker.wake();
}
glib::Continue(false)
glib::ControlFlow::Break
},
);
let main_context = glib::MainContext::ref_thread_default();
Expand Down Expand Up @@ -235,7 +235,7 @@ impl<T: IsA<PollableOutputStream>> AsyncWrite for OutputStreamAsyncWrite<T> {
if let Some(waker) = waker.take() {
waker.wake();
}
glib::Continue(false)
glib::ControlFlow::Break
},
);
let main_context = glib::MainContext::ref_thread_default();
Expand Down
10 changes: 5 additions & 5 deletions gio/src/socket.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Take a look at the license at the top of the repository in the LICENSE file.

#[cfg(not(unix))]
use std::os::raw::c_int;

Check warning on line 4 in gio/src/socket.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (examples, false, --bins --examples --all-features)

unused import: `std::os::raw::c_int`

Check warning on line 4 in gio/src/socket.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (gdk-pixbuf, true, --features v2_42)

unused import: `std::os::raw::c_int`

Check warning on line 4 in gio/src/socket.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (gdk-pixbuf, true, --features v2_42)

unused import: `std::os::raw::c_int`

Check warning on line 4 in gio/src/socket.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (pango, true, --features v1_50)

unused import: `std::os::raw::c_int`

Check warning on line 4 in gio/src/socket.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (pango, true, --features v1_50)

unused import: `std::os::raw::c_int`

Check warning on line 4 in gio/src/socket.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (gio, true, --features v2_74)

unused import: `std::os::raw::c_int`

Check warning on line 4 in gio/src/socket.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (gio, true, --features v2_74)

unused import: `std::os::raw::c_int`

Check warning on line 4 in gio/src/socket.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (pangocairo, true)

unused import: `std::os::raw::c_int`

Check warning on line 4 in gio/src/socket.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (pangocairo, true)

unused import: `std::os::raw::c_int`
#[cfg(unix)]
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
#[cfg(windows)]
Expand Down Expand Up @@ -663,12 +663,12 @@
func: F,
) -> glib::Source
where
F: FnMut(&Self, glib::IOCondition) -> glib::Continue + 'static,
F: FnMut(&Self, glib::IOCondition) -> glib::ControlFlow + 'static,
C: IsA<Cancellable>,
{
unsafe extern "C" fn trampoline<
O: IsA<Socket>,
F: FnMut(&O, glib::IOCondition) -> glib::Continue + 'static,
F: FnMut(&O, glib::IOCondition) -> glib::ControlFlow + 'static,
>(
socket: *mut ffi::GSocket,
condition: glib::ffi::GIOCondition,
Expand Down Expand Up @@ -731,7 +731,7 @@
priority,
move |_, condition| {
let _ = send.take().unwrap().send(condition);
glib::Continue(false)
glib::ControlFlow::Break
},
)
}))
Expand All @@ -755,9 +755,9 @@
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
}
},
)
Expand Down
36 changes: 18 additions & 18 deletions glib/src/main_context_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -197,14 +197,14 @@ impl<T> Channel<T> {
}

#[repr(C)]
struct ChannelSource<T, F: FnMut(T) -> Continue + 'static> {
struct ChannelSource<T, F: FnMut(T) -> ControlFlow + 'static> {
source: ffi::GSource,
source_funcs: Box<ffi::GSourceFuncs>,
channel: Channel<T>,
callback: ThreadGuard<F>,
}

unsafe extern "C" fn dispatch<T, F: FnMut(T) -> Continue + 'static>(
unsafe extern "C" fn dispatch<T, F: FnMut(T) -> ControlFlow + 'static>(
source: *mut ffi::GSource,
callback: ffi::GSourceFunc,
_user_data: ffi::gpointer,
Expand All @@ -228,7 +228,7 @@ unsafe extern "C" fn dispatch<T, F: FnMut(T) -> 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;
}
}
Expand All @@ -239,7 +239,7 @@ unsafe extern "C" fn dispatch<T, F: FnMut(T) -> Continue + 'static>(
}

#[cfg(feature = "v2_64")]
unsafe extern "C" fn dispose<T, F: FnMut(T) -> Continue + 'static>(source: *mut ffi::GSource) {
unsafe extern "C" fn dispose<T, F: FnMut(T) -> ControlFlow + 'static>(source: *mut ffi::GSource) {
let source = &mut *(source as *mut ChannelSource<T, F>);

// Set the source inside the channel to None so that all senders know that there
Expand All @@ -251,7 +251,7 @@ unsafe extern "C" fn dispose<T, F: FnMut(T) -> Continue + 'static>(source: *mut
}
}

unsafe extern "C" fn finalize<T, F: FnMut(T) -> Continue + 'static>(source: *mut ffi::GSource) {
unsafe extern "C" fn finalize<T, F: FnMut(T) -> ControlFlow + 'static>(source: *mut ffi::GSource) {
let source = &mut *(source as *mut ChannelSource<T, F>);

// Drop all memory we own by taking it out of the Options
Expand Down Expand Up @@ -453,7 +453,7 @@ impl<T> Receiver<T> {
///
/// 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<F: FnMut(T) -> Continue + 'static>(
pub fn attach<F: FnMut(T) -> ControlFlow + 'static>(
mut self,
context: Option<&MainContext>,
func: F,
Expand Down Expand Up @@ -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
}
});

Expand Down Expand Up @@ -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);
Expand All @@ -657,7 +657,7 @@ mod tests {

let (sender, receiver) = MainContext::channel::<i32>(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();
Expand All @@ -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();
Expand Down Expand Up @@ -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
}
});

Expand Down Expand Up @@ -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
}
});

Expand Down Expand Up @@ -873,15 +873,15 @@ 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
assert_eq!(
wait_receiver.recv_timeout(time::Duration::from_millis(50)),
Err(mpsc::RecvTimeoutError::Timeout)
);
Continue(true)
ControlFlow::Continue
}
});
l.run();
Expand Down
4 changes: 2 additions & 2 deletions glib/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Loading
Loading