Skip to content

Commit d593925

Browse files
authored
Merge pull request #826 from jf2048/into-value-variant
Implement From<T> for Value, Variant
2 parents a859829 + b6e70df commit d593925

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1597
-115
lines changed

cairo/src/context.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ impl fmt::Display for RectangleList {
7171
#[repr(transparent)]
7272
pub struct Context(ptr::NonNull<cairo_t>);
7373

74+
#[cfg(feature = "use_glib")]
75+
impl IntoGlibPtr<*mut ffi::cairo_t> for Context {
76+
#[inline]
77+
unsafe fn into_glib_ptr(self) -> *mut ffi::cairo_t {
78+
(&*std::mem::ManuallyDrop::new(self)).to_glib_none().0
79+
}
80+
}
81+
7482
#[cfg(feature = "use_glib")]
7583
impl<'a> ToGlibPtr<'a, *mut ffi::cairo_t> for &'a Context {
7684
type Storage = &'a Context;

cairo/src/device.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,14 @@ impl Device {
311311
}
312312
}
313313

314+
#[cfg(feature = "use_glib")]
315+
impl IntoGlibPtr<*mut ffi::cairo_device_t> for Device {
316+
#[inline]
317+
unsafe fn into_glib_ptr(self) -> *mut ffi::cairo_device_t {
318+
std::mem::ManuallyDrop::new(self).to_glib_none().0
319+
}
320+
}
321+
314322
#[cfg(feature = "use_glib")]
315323
impl<'a> ToGlibPtr<'a, *mut ffi::cairo_device_t> for Device {
316324
type Storage = &'a Device;

cairo/src/enums.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ macro_rules! gvalue_impl {
4242
<Self as glib::StaticType>::static_type()
4343
}
4444
}
45+
46+
impl From<$name> for glib::Value {
47+
#[inline]
48+
fn from(v: $name) -> Self {
49+
glib::value::ToValue::to_value(&v)
50+
}
51+
}
4552
};
4653
}
4754

cairo/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ macro_rules! gvalue_impl {
8686
}
8787
}
8888

89+
impl From<$name> for glib::Value {
90+
fn from(v: $name) -> Self {
91+
unsafe {
92+
let mut value =
93+
glib::Value::from_type(<$name as glib::StaticType>::static_type());
94+
glib::gobject_ffi::g_value_take_boxed(
95+
value.to_glib_none_mut().0,
96+
glib::translate::IntoGlibPtr::into_glib_ptr(v) as *mut _,
97+
);
98+
value
99+
}
100+
}
101+
}
102+
89103
impl glib::value::ToValueOptional for $name {
90104
fn to_value_optional(s: Option<&Self>) -> glib::Value {
91105
let mut value = glib::Value::for_value_type::<Self>();

cairo/src/region.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ use crate::ffi::cairo_region_t;
1515
#[repr(transparent)]
1616
pub struct Region(ptr::NonNull<cairo_region_t>);
1717

18+
#[cfg(feature = "use_glib")]
19+
impl IntoGlibPtr<*mut ffi::cairo_region_t> for Region {
20+
#[inline]
21+
unsafe fn into_glib_ptr(self) -> *mut ffi::cairo_region_t {
22+
(&*std::mem::ManuallyDrop::new(self)).to_glib_none().0
23+
}
24+
}
25+
1826
#[cfg(feature = "use_glib")]
1927
#[doc(hidden)]
2028
impl<'a> ToGlibPtr<'a, *mut ffi::cairo_region_t> for &'a Region {

cairo/src/surface.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,14 @@ impl Surface {
289289
}
290290
}
291291

292+
#[cfg(feature = "use_glib")]
293+
impl IntoGlibPtr<*mut ffi::cairo_surface_t> for Surface {
294+
#[inline]
295+
unsafe fn into_glib_ptr(self) -> *mut ffi::cairo_surface_t {
296+
std::mem::ManuallyDrop::new(self).to_glib_none().0
297+
}
298+
}
299+
292300
#[cfg(feature = "use_glib")]
293301
impl<'a> ToGlibPtr<'a, *mut ffi::cairo_surface_t> for Surface {
294302
type Storage = &'a Surface;

cairo/src/surface_macros.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ macro_rules! declare_surface {
3535
}
3636
}
3737

38+
#[cfg(feature = "use_glib")]
39+
impl IntoGlibPtr<*mut ffi::cairo_surface_t> for $surf_name {
40+
#[inline]
41+
unsafe fn into_glib_ptr(self) -> *mut ffi::cairo_surface_t {
42+
std::mem::ManuallyDrop::new(self).to_glib_none().0
43+
}
44+
}
45+
3846
#[cfg(feature = "use_glib")]
3947
impl<'a> ToGlibPtr<'a, *mut ffi::cairo_surface_t> for $surf_name {
4048
type Storage = &'a Surface;

gdk-pixbuf/src/auto/enums.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ impl ToValue for Colorspace {
8888
}
8989
}
9090

91+
impl From<Colorspace> for glib::Value {
92+
#[inline]
93+
fn from(v: Colorspace) -> Self {
94+
ToValue::to_value(&v)
95+
}
96+
}
97+
9198
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
9299
#[non_exhaustive]
93100
#[doc(alias = "GdkInterpType")]
@@ -180,6 +187,13 @@ impl ToValue for InterpType {
180187
}
181188
}
182189

190+
impl From<InterpType> for glib::Value {
191+
#[inline]
192+
fn from(v: InterpType) -> Self {
193+
ToValue::to_value(&v)
194+
}
195+
}
196+
183197
#[cfg_attr(feature = "v2_42", deprecated = "Since 2.42")]
184198
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
185199
#[non_exhaustive]
@@ -263,6 +277,13 @@ impl ToValue for PixbufAlphaMode {
263277
}
264278
}
265279

280+
impl From<PixbufAlphaMode> for glib::Value {
281+
#[inline]
282+
fn from(v: PixbufAlphaMode) -> Self {
283+
ToValue::to_value(&v)
284+
}
285+
}
286+
266287
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
267288
#[non_exhaustive]
268289
#[doc(alias = "GdkPixbufError")]
@@ -393,6 +414,13 @@ impl ToValue for PixbufError {
393414
}
394415
}
395416

417+
impl From<PixbufError> for glib::Value {
418+
#[inline]
419+
fn from(v: PixbufError) -> Self {
420+
ToValue::to_value(&v)
421+
}
422+
}
423+
396424
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
397425
#[non_exhaustive]
398426
#[doc(alias = "GdkPixbufRotation")]
@@ -484,3 +512,10 @@ impl ToValue for PixbufRotation {
484512
Self::static_type()
485513
}
486514
}
515+
516+
impl From<PixbufRotation> for glib::Value {
517+
#[inline]
518+
fn from(v: PixbufRotation) -> Self {
519+
ToValue::to_value(&v)
520+
}
521+
}

gdk-pixbuf/src/auto/versions.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Generated by gir (https://github.com/gtk-rs/gir @ e94fdc6499e4)
2-
from gir-files (https://github.com/gtk-rs/gir-files @ 3b6fe0a33676)
1+
Generated by gir (https://github.com/gtk-rs/gir @ 0eeebbdf9d4d)
2+
from gir-files (https://github.com/gtk-rs/gir-files @ d8382a5920b8)

gdk-pixbuf/sys/versions.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Generated by gir (https://github.com/gtk-rs/gir @ e94fdc6499e4)
2-
from gir-files (https://github.com/gtk-rs/gir-files @ 3b6fe0a33676)
1+
Generated by gir (https://github.com/gtk-rs/gir @ 0eeebbdf9d4d)
2+
from gir-files (https://github.com/gtk-rs/gir-files @ d8382a5920b8)

0 commit comments

Comments
 (0)