pango/
rectangle.rs

1// Copyright 2015, The Gtk-rs Project Developers.
2// See the COPYRIGHT file at the top-level directory of this distribution.
3// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
4
5use glib::translate::*;
6use pango_sys;
7use std::mem;
8
9#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
10#[repr(C)]
11pub struct Rectangle {
12    pub x: i32,
13    pub y: i32,
14    pub width: i32,
15    pub height: i32,
16}
17
18impl Rectangle {
19    pub fn new(x: i32, y: i32, width: i32, height: i32) -> Rectangle {
20        Rectangle {
21            x,
22            y,
23            width,
24            height,
25        }
26    }
27}
28
29#[doc(hidden)]
30impl Uninitialized for Rectangle {
31    #[inline]
32    unsafe fn uninitialized() -> Self {
33        mem::uninitialized()
34    }
35}
36
37#[doc(hidden)]
38impl<'a> ToGlibPtr<'a, *const pango_sys::PangoRectangle> for Rectangle {
39    type Storage = &'a Self;
40
41    #[inline]
42    fn to_glib_none(&'a self) -> Stash<'a, *const pango_sys::PangoRectangle, Self> {
43        let ptr: *const Rectangle = &*self;
44        Stash(ptr as *const pango_sys::PangoRectangle, self)
45    }
46}
47
48#[doc(hidden)]
49impl<'a> ToGlibPtrMut<'a, *mut pango_sys::PangoRectangle> for Rectangle {
50    type Storage = &'a mut Self;
51
52    #[inline]
53    fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut pango_sys::PangoRectangle, Self> {
54        let ptr: *mut Rectangle = &mut *self;
55        StashMut(ptr as *mut pango_sys::PangoRectangle, self)
56    }
57}
58
59#[doc(hidden)]
60impl FromGlibPtrNone<*const pango_sys::PangoRectangle> for Rectangle {
61    unsafe fn from_glib_none(ptr: *const pango_sys::PangoRectangle) -> Self {
62        *(ptr as *const Rectangle)
63    }
64}
65
66#[doc(hidden)]
67impl FromGlibPtrNone<*mut pango_sys::PangoRectangle> for Rectangle {
68    unsafe fn from_glib_none(ptr: *mut pango_sys::PangoRectangle) -> Self {
69        *(ptr as *mut Rectangle)
70    }
71}