cairo/
rectangle.rs

1use ffi;
2#[cfg(feature = "use_glib")]
3use glib::translate::*;
4use std::fmt;
5#[cfg(feature = "use_glib")]
6use std::mem;
7
8#[derive(Clone, Copy, Debug, PartialEq)]
9#[repr(C)]
10pub struct Rectangle {
11    pub x: f64,
12    pub y: f64,
13    pub width: f64,
14    pub height: f64,
15}
16
17#[cfg(feature = "use_glib")]
18#[doc(hidden)]
19impl Uninitialized for Rectangle {
20    #[inline]
21    unsafe fn uninitialized() -> Self {
22        mem::uninitialized()
23    }
24}
25
26#[cfg(feature = "use_glib")]
27#[doc(hidden)]
28impl<'a> ToGlibPtr<'a, *const ffi::cairo_rectangle_t> for Rectangle {
29    type Storage = &'a Self;
30
31    #[inline]
32    fn to_glib_none(&'a self) -> Stash<'a, *const ffi::cairo_rectangle_t, Self> {
33        let ptr: *const Rectangle = &*self;
34        Stash(ptr as *const ffi::cairo_rectangle_t, self)
35    }
36}
37
38#[cfg(feature = "use_glib")]
39#[doc(hidden)]
40impl<'a> ToGlibPtrMut<'a, *mut ffi::cairo_rectangle_t> for Rectangle {
41    type Storage = &'a mut Self;
42
43    #[inline]
44    fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ffi::cairo_rectangle_t, Self> {
45        let ptr: *mut Rectangle = &mut *self;
46        StashMut(ptr as *mut ffi::cairo_rectangle_t, self)
47    }
48}
49
50#[cfg(feature = "use_glib")]
51#[doc(hidden)]
52impl FromGlibPtrNone<*const ffi::cairo_rectangle_t> for Rectangle {
53    unsafe fn from_glib_none(ptr: *const ffi::cairo_rectangle_t) -> Self {
54        *(ptr as *const Rectangle)
55    }
56}
57
58#[cfg(feature = "use_glib")]
59#[doc(hidden)]
60impl FromGlibPtrBorrow<*mut ffi::cairo_rectangle_t> for Rectangle {
61    unsafe fn from_glib_borrow(ptr: *mut ffi::cairo_rectangle_t) -> Self {
62        *(ptr as *mut Rectangle)
63    }
64}
65
66#[cfg(feature = "use_glib")]
67#[doc(hidden)]
68impl FromGlibPtrNone<*mut ffi::cairo_rectangle_t> for Rectangle {
69    unsafe fn from_glib_none(ptr: *mut ffi::cairo_rectangle_t) -> Self {
70        *(ptr as *mut Rectangle)
71    }
72}
73
74#[cfg(feature = "use_glib")]
75gvalue_impl!(
76    Rectangle,
77    ffi::cairo_rectangle_t,
78    ffi::gobject::cairo_gobject_rectangle_get_type
79);
80
81impl Rectangle {
82    pub fn to_raw_none(&self) -> *mut ffi::cairo_rectangle_t {
83        let ptr = &*self as *const Rectangle as usize;
84        ptr as *mut ffi::cairo_rectangle_t
85    }
86}
87
88impl fmt::Display for Rectangle {
89    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
90        write!(f, "Rectangle")
91    }
92}