1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
use ffi; use glib; use glib::translate::*; use libc::c_char; use std::mem; use std::ffi::CStr; use TargetFlags; #[derive(Clone, Debug)] #[repr(C)] pub struct TargetEntry { target: String, flags: TargetFlags, info: u32, } impl TargetEntry { pub fn new(target: &str, flags: TargetFlags, info: u32) -> TargetEntry { assert_initialized_main_thread!(); TargetEntry { target: target.to_owned(), flags: flags, info: info, } } pub fn get_target(&self) -> &str { &self.target } pub fn get_flags(&self) -> TargetFlags { self.flags } pub fn get_info(&self) -> u32 { self.info } } #[doc(hidden)] impl Uninitialized for TargetEntry { #[inline] unsafe fn uninitialized() -> Self { mem::uninitialized() } } #[doc(hidden)] impl<'a> ToGlibPtr<'a, *const ffi::GtkTargetEntry> for TargetEntry { type Storage = (Box<ffi::GtkTargetEntry>, Stash<'a, *mut c_char, String>); #[inline] fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GtkTargetEntry, Self> { let target = self.target.to_glib_none(); let mut target_entry = Box::new(ffi::GtkTargetEntry { target: target.0, flags: self.flags.bits(), info: self.info, }); Stash(&mut *target_entry, (target_entry, target)) } } #[doc(hidden)] impl<'a> ToGlibPtrMut<'a, *mut ffi::GtkTargetEntry> for TargetEntry { type Storage = (Box<ffi::GtkTargetEntry>, Stash<'a, *mut c_char, String>); #[inline] fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ffi::GtkTargetEntry, Self> { let target = self.target.to_glib_none(); let mut target_entry = Box::new(ffi::GtkTargetEntry { target: target.0, flags: self.flags.bits(), info: self.info, }); StashMut(&mut *target_entry, (target_entry, target)) } } #[doc(hidden)] impl FromGlibPtrNone<*const ffi::GtkTargetEntry> for TargetEntry { unsafe fn from_glib_none(ptr: *const ffi::GtkTargetEntry) -> Self { TargetEntry { target: CStr::from_ptr((*ptr).target).to_string_lossy().into_owned(), flags: TargetFlags::from_bits((*ptr).flags).unwrap(), info: (*ptr).info, } } } #[doc(hidden)] impl FromGlibPtrNone<*mut ffi::GtkTargetEntry> for TargetEntry { unsafe fn from_glib_none(ptr: *mut ffi::GtkTargetEntry) -> Self { TargetEntry { target: CStr::from_ptr((*ptr).target).to_string_lossy().into_owned(), flags: TargetFlags::from_bits((*ptr).flags).unwrap(), info: (*ptr).info, } } } #[doc(hidden)] impl FromGlibPtrFull<*mut ffi::GtkTargetEntry> for TargetEntry { #[inline] unsafe fn from_glib_full(ptr: *mut ffi::GtkTargetEntry) -> Self { let target_entry = TargetEntry { target: CStr::from_ptr((*ptr).target).to_string_lossy().into_owned(), flags: TargetFlags::from_bits((*ptr).flags).unwrap(), info: (*ptr).info, }; ffi::gtk_target_entry_free(ptr); target_entry } } impl glib::StaticType for TargetEntry { fn static_type() -> glib::types::Type { skip_assert_initialized!(); unsafe { from_glib(ffi::gtk_target_entry_get_type()) } } }