diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 83cb0cf46a14..f49b73641ff0 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -23,7 +23,7 @@ jobs: - { name: "cairo", features: "png,pdf,svg,ps,use_glib,v1_18,freetype,script,xcb,xlib,win32-surface", nightly: "--features 'png,pdf,svg,ps,use_glib,v1_18,freetype,script,xcb,xlib,win32-surface'", test_sys: true } - { name: "gdk-pixbuf", features: "v2_42", nightly: "--all-features", test_sys: true } - { name: "gio", features: "v2_74", nightly: "--all-features", test_sys: true } - - { name: "glib", features: "v2_74", nightly: "--all-features", test_sys: true } + - { name: "glib", features: "v2_74", nightly: "--features=v2_76,log,log_macros,compiletests", test_sys: true } - { name: "graphene", features: "", nightly: "", test_sys: true } - { name: "pango", features: "v1_50", nightly: "--all-features", test_sys: true } - { name: "pangocairo", features: "", nightly: "--all-features", test_sys: true } diff --git a/glib/Cargo.toml b/glib/Cargo.toml index c3874ab2c154..3dfd83399aec 100644 --- a/glib/Cargo.toml +++ b/glib/Cargo.toml @@ -58,6 +58,7 @@ log = ["rs-log"] log_macros = ["log"] compiletests = [] gio = ["gio_ffi"] +std_once_cell = [] [package.metadata.docs.rs] all-features = true diff --git a/glib/src/property.rs b/glib/src/property.rs index 53ff6578bdb6..e407677dac91 100644 --- a/glib/src/property.rs +++ b/glib/src/property.rs @@ -47,6 +47,14 @@ impl Property for once_cell::sync::OnceCell { impl Property for once_cell::unsync::OnceCell { type Value = T::Value; } +#[cfg(feature = "std_once_cell")] +impl Property for std::cell::OnceCell { + type Value = T::Value; +} +#[cfg(feature = "std_once_cell")] +impl Property for std::sync::OnceLock { + type Value = T::Value; +} // Handle smart pointers trasparently impl Property for Rc { type Value = T::Value; @@ -179,6 +187,41 @@ impl PropertySet for once_cell::unsync::OnceCell { } } +#[cfg(feature = "std_once_cell")] +impl PropertyGet for std::cell::OnceCell { + type Value = T; + fn get R>(&self, f: F) -> R { + f(self.get().unwrap()) + } +} +#[cfg(feature = "std_once_cell")] +impl PropertyGet for std::sync::OnceLock { + type Value = T; + fn get R>(&self, f: F) -> R { + f(self.get().unwrap()) + } +} +#[cfg(feature = "std_once_cell")] +impl PropertySet for std::cell::OnceCell { + type SetValue = T; + fn set(&self, v: Self::SetValue) { + // I can't use `unwrap` because I would have to add a `Debug` bound to _v + if let Err(_v) = self.set(v) { + panic!("can't set value of OnceCell multiple times") + }; + } +} +#[cfg(feature = "std_once_cell")] +impl PropertySet for std::sync::OnceLock { + type SetValue = T; + fn set(&self, v: Self::SetValue) { + // I can't use `unwrap` because I would have to add a `Debug` bound to _v + if let Err(_v) = self.set(v) { + panic!("can't set value of OnceCell multiple times") + }; + } +} + impl> PropertyGet for WeakRef { type Value = Option;