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: Remove Inhibit and replace it with ControlFlow #1126

Merged
merged 4 commits 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
2 changes: 1 addition & 1 deletion gdk-pixbuf/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ c659c2b21954)
Generated by gir (https://github.com/gtk-rs/gir @ c88b69265102)
from gir-files (https://github.com/gtk-rs/gir-files @ 744be9fbbbed)
2 changes: 1 addition & 1 deletion gdk-pixbuf/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ c659c2b21954)
Generated by gir (https://github.com/gtk-rs/gir @ c88b69265102)
from gir-files (https://github.com/gtk-rs/gir-files @ 744be9fbbbed)
4 changes: 2 additions & 2 deletions gio/src/auto/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,13 +515,13 @@ pub trait SettingsExt: IsA<Settings> + sealed::Sealed + 'static {
}

#[doc(alias = "writable-change-event")]
fn connect_writable_change_event<F: Fn(&Self, u32) -> glib::signal::Inhibit + 'static>(
fn connect_writable_change_event<F: Fn(&Self, u32) -> glib::ControlFlow + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn writable_change_event_trampoline<
P: IsA<Settings>,
F: Fn(&P, u32) -> glib::signal::Inhibit + 'static,
F: Fn(&P, u32) -> glib::ControlFlow + 'static,
>(
this: *mut ffi::GSettings,
key: libc::c_uint,
Expand Down
2 changes: 1 addition & 1 deletion gio/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ c659c2b21954)
Generated by gir (https://github.com/gtk-rs/gir @ c88b69265102)
from gir-files (https://github.com/gtk-rs/gir-files @ 744be9fbbbed)
2 changes: 1 addition & 1 deletion gio/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ c659c2b21954)
Generated by gir (https://github.com/gtk-rs/gir @ c88b69265102)
from gir-files (https://github.com/gtk-rs/gir-files @ 744be9fbbbed)
2 changes: 1 addition & 1 deletion gir
Submodule gir updated 1 files
+2 −2 src/codegen/trampoline.rs
2 changes: 1 addition & 1 deletion glib/gobject-sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ c659c2b21954)
Generated by gir (https://github.com/gtk-rs/gir @ c88b69265102)
from gir-files (https://github.com/gtk-rs/gir-files @ 744be9fbbbed)
2 changes: 1 addition & 1 deletion glib/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ c659c2b21954)
Generated by gir (https://github.com/gtk-rs/gir @ c88b69265102)
from gir-files (https://github.com/gtk-rs/gir-files @ 744be9fbbbed)
103 changes: 103 additions & 0 deletions glib/src/control_flow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::translate::*;

// rustdoc-stripper-ignore-next
/// Continue calling the closure in the future iterations or drop it.
///
/// This is the return type of `idle_add` and `timeout_add` closures.
///
/// `ControlFlow::Continue` keeps the closure assigned, to be rerun when appropriate.
///
/// `ControlFlow::Break` disconnects and drops it.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
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<std::ops::ControlFlow<()>> 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<ControlFlow> for std::ops::ControlFlow<()> {
fn from(c: ControlFlow) -> Self {
match c {
ControlFlow::Break => Self::Break(()),
ControlFlow::Continue => Self::Continue(()),
}
}
}

impl From<bool> for ControlFlow {
fn from(c: bool) -> Self {
if c {
Self::Continue
} else {
Self::Break
}
}
}

impl From<ControlFlow> for bool {
fn from(c: ControlFlow) -> Self {
match c {
ControlFlow::Break => false,
ControlFlow::Continue => true,
}
}
}

#[doc(hidden)]
impl IntoGlib for ControlFlow {
type GlibType = ffi::gboolean;

#[inline]
fn into_glib(self) -> ffi::gboolean {
bool::from(self).into_glib()
}
}

#[doc(hidden)]
impl FromGlib<ffi::gboolean> for ControlFlow {
#[inline]
unsafe fn from_glib(value: ffi::gboolean) -> Self {
bool::from_glib(value).into()
}
}

impl crate::ToValue for ControlFlow {
fn to_value(&self) -> crate::Value {
bool::from(*self).to_value()
}

fn value_type(&self) -> crate::Type {
<bool as crate::StaticType>::static_type()
}
}

impl From<ControlFlow> for crate::Value {
#[inline]
fn from(v: ControlFlow) -> Self {
v.into()
}
}
2 changes: 2 additions & 0 deletions glib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@

mod byte_array;
mod bytes;
mod control_flow;
pub use self::control_flow::ControlFlow;
pub mod char;
pub use self::char::*;
mod checksum;
Expand All @@ -129,7 +131,7 @@
mod convert;
pub use self::convert::*;
mod enums;
mod functions;

Check warning on line 134 in glib/src/lib.rs

View workflow job for this annotation

GitHub Actions / build

private item shadows public glob re-export
pub use self::functions::*;
mod key_file;
pub mod prelude;
Expand Down
36 changes: 1 addition & 35 deletions glib/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use std::{mem, num::NonZeroU64};

use ffi::{gboolean, gpointer};
use ffi::gpointer;
use gobject_ffi::{self, GCallback};
use libc::{c_char, c_ulong, c_void};

Expand Down Expand Up @@ -65,40 +65,6 @@ impl FromGlib<c_ulong> for SignalHandlerId {
}
}

// rustdoc-stripper-ignore-next
/// Whether to propagate the signal to the default handler.
///
/// Don't inhibit default handlers without a reason, they're usually helpful.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct Inhibit(pub bool);

#[doc(hidden)]
impl IntoGlib for Inhibit {
type GlibType = gboolean;

#[inline]
fn into_glib(self) -> gboolean {
self.0.into_glib()
}
}

impl crate::ToValue for Inhibit {
fn to_value(&self) -> crate::Value {
self.0.to_value()
}

fn value_type(&self) -> crate::Type {
<bool as crate::StaticType>::static_type()
}
}

impl From<Inhibit> for crate::Value {
#[inline]
fn from(v: Inhibit) -> Self {
v.0.into()
}
}

pub unsafe fn connect_raw<F>(
receiver: *mut gobject_ffi::GObject,
signal_name: *const c_char,
Expand Down
77 changes: 1 addition & 76 deletions glib/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use libc::c_int as RawFd;

#[cfg(any(unix, docsrs))]
use crate::IOCondition;
use crate::{thread_guard::ThreadGuard, translate::*, MainContext, Source};
use crate::{thread_guard::ThreadGuard, translate::*, ControlFlow, MainContext, Source};

// rustdoc-stripper-ignore-next
/// The id of a source that is returned by `idle_add` and `timeout_add`.
Expand Down Expand Up @@ -79,81 +79,6 @@ impl FromGlib<ffi::GPid> for Pid {
}
}

// rustdoc-stripper-ignore-next
/// Continue calling the closure in the future iterations or drop it.
///
/// This is the return type of `idle_add` and `timeout_add` closures.
///
/// `ControlFlow::Continue` keeps the closure assigned, to be rerun when appropriate.
///
/// `ControlFlow::Break` disconnects and drops it.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
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<std::ops::ControlFlow<()>> 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<ControlFlow> for std::ops::ControlFlow<()> {
fn from(c: ControlFlow) -> Self {
match c {
ControlFlow::Break => Self::Break(()),
ControlFlow::Continue => Self::Continue(()),
}
}
}

impl From<bool> for ControlFlow {
fn from(c: bool) -> Self {
if c {
Self::Continue
} else {
Self::Break
}
}
}

impl From<ControlFlow> for bool {
fn from(c: ControlFlow) -> Self {
match c {
ControlFlow::Break => false,
ControlFlow::Continue => true,
}
}
}

#[doc(hidden)]
impl IntoGlib for ControlFlow {
type GlibType = gboolean;

#[inline]
fn into_glib(self) -> gboolean {
bool::from(self).into_glib()
}
}

unsafe extern "C" fn trampoline<F: FnMut() -> ControlFlow + Send + 'static>(
func: gpointer,
) -> gboolean {
Expand Down
2 changes: 1 addition & 1 deletion glib/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ c659c2b21954)
Generated by gir (https://github.com/gtk-rs/gir @ c88b69265102)
from gir-files (https://github.com/gtk-rs/gir-files @ 744be9fbbbed)
2 changes: 1 addition & 1 deletion graphene/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ c659c2b21954)
Generated by gir (https://github.com/gtk-rs/gir @ c88b69265102)
from gir-files (https://github.com/gtk-rs/gir-files @ 744be9fbbbed)
2 changes: 1 addition & 1 deletion graphene/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ c659c2b21954)
Generated by gir (https://github.com/gtk-rs/gir @ c88b69265102)
from gir-files (https://github.com/gtk-rs/gir-files @ 744be9fbbbed)
2 changes: 1 addition & 1 deletion pango/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ c659c2b21954)
Generated by gir (https://github.com/gtk-rs/gir @ c88b69265102)
from gir-files (https://github.com/gtk-rs/gir-files @ 744be9fbbbed)
2 changes: 1 addition & 1 deletion pango/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ c659c2b21954)
Generated by gir (https://github.com/gtk-rs/gir @ c88b69265102)
from gir-files (https://github.com/gtk-rs/gir-files @ 744be9fbbbed)
2 changes: 1 addition & 1 deletion pangocairo/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ c659c2b21954)
Generated by gir (https://github.com/gtk-rs/gir @ c88b69265102)
from gir-files (https://github.com/gtk-rs/gir-files @ 744be9fbbbed)
2 changes: 1 addition & 1 deletion pangocairo/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ c659c2b21954)
Generated by gir (https://github.com/gtk-rs/gir @ c88b69265102)
from gir-files (https://github.com/gtk-rs/gir-files @ 744be9fbbbed)
Loading