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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
use crate::{AttrClass, AttrType, Attribute};
use glib::translate::*;
impl Attribute {
#[doc(alias = "get_attr_class")]
pub fn attr_class(&self) -> AttrClass {
unsafe { from_glib_full((*self.to_glib_none().0).klass) }
}
pub fn type_(&self) -> AttrType {
unsafe { from_glib((*(*self.to_glib_none().0).klass).type_) }
}
#[doc(alias = "get_start_index")]
pub fn start_index(&self) -> u32 {
unsafe {
let stash = self.to_glib_none();
(*stash.0).start_index
}
}
#[doc(alias = "get_end_index")]
pub fn end_index(&self) -> u32 {
unsafe {
let stash = self.to_glib_none();
(*stash.0).end_index
}
}
pub fn set_start_index(&mut self, index: u32) {
unsafe {
let stash = self.to_glib_none_mut();
(*stash.0).start_index = index;
}
}
pub fn set_end_index(&mut self, index: u32) {
unsafe {
let stash = self.to_glib_none_mut();
(*stash.0).end_index = index;
}
}
pub fn downcast<T: IsAttribute>(self) -> Result<T, Attribute> {
unsafe {
if T::ATTR_TYPES.contains(&self.attr_class().type_()) {
Ok(from_glib_full(self.to_glib_full()))
} else {
Err(self)
}
}
}
pub fn downcast_ref<T: IsAttribute>(&self) -> Option<&T> {
unsafe {
if T::ATTR_TYPES.contains(&self.attr_class().type_()) {
Some(&*(self as *const Attribute as *const T))
} else {
None
}
}
}
}
pub unsafe trait IsAttribute:
FromGlibPtrFull<*const ffi::PangoAttribute>
+ FromGlibPtrFull<*mut ffi::PangoAttribute>
+ std::convert::AsRef<crate::Attribute>
+ 'static
{
const ATTR_TYPES: &'static [AttrType];
fn upcast(self) -> Attribute;
fn upcast_ref(&self) -> &Attribute;
}
macro_rules! define_attribute_struct {
($rust_type:ident, $ffi_type:path, $attr_types:expr) => {
#[cfg(any(feature = "v1_44", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))]
glib::wrapper! {
#[derive(Debug)]
pub struct $rust_type(Boxed<$ffi_type>);
match fn {
copy => |ptr| ffi::pango_attribute_copy(ptr as *const ffi::PangoAttribute) as *mut $ffi_type,
free => |ptr| ffi::pango_attribute_destroy(ptr as *mut ffi::PangoAttribute),
type_ => || ffi::pango_attribute_get_type(),
}
}
unsafe impl Send for $rust_type {}
unsafe impl Sync for $rust_type {}
#[cfg(not(any(feature = "v1_44", feature = "dox")))]
glib::wrapper! {
#[derive(Debug)]
pub struct $rust_type(Boxed<$ffi_type>);
match fn {
copy => |ptr| ffi::pango_attribute_copy(ptr as *const ffi::PangoAttribute) as *mut $ffi_type,
free => |ptr| ffi::pango_attribute_destroy(ptr as *mut ffi::PangoAttribute),
}
}
impl $rust_type {
#[doc(alias = "pango_attribute_equal")]
fn equal<'a, T: crate::attribute::IsAttribute>(&self, attr2: &'a T) -> bool {
unsafe {
glib::translate::from_glib(ffi::pango_attribute_equal(
glib::translate::ToGlibPtr::to_glib_none(self).0 as *const ffi::PangoAttribute,
glib::translate::ToGlibPtr::to_glib_none(attr2.upcast_ref()).0 as *const ffi::PangoAttribute,
))
}
}
}
impl PartialEq for $rust_type {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.equal(other)
}
}
impl Eq for $rust_type {}
unsafe impl crate::attribute::IsAttribute for $rust_type {
const ATTR_TYPES: &'static [crate::AttrType] = $attr_types;
fn upcast(self) -> crate::Attribute {
unsafe { glib::translate::from_glib_full(glib::translate::ToGlibPtr::to_glib_full(&self) as *mut ffi::PangoAttribute) }
}
fn upcast_ref(&self) -> &crate::Attribute {
&*self
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrFull<*mut ffi::PangoAttribute> for $rust_type {
unsafe fn from_glib_full(ptr: *mut ffi::PangoAttribute) -> Self {
glib::translate::from_glib_full(ptr as *mut $ffi_type)
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrFull<*const ffi::PangoAttribute> for $rust_type {
unsafe fn from_glib_full(ptr: *const ffi::PangoAttribute) -> Self {
glib::translate::from_glib_full(ptr as *const $ffi_type)
}
}
impl std::convert::AsRef<crate::Attribute> for $rust_type {
fn as_ref(&self) -> &crate::Attribute {
&*self
}
}
impl From<$rust_type> for crate::Attribute {
fn from(attr: $rust_type) -> crate::Attribute {
crate::IsAttribute::upcast(attr)
}
}
impl std::ops::Deref for $rust_type {
type Target = crate::Attribute;
fn deref(&self) -> &Self::Target {
unsafe { &*(self as *const $rust_type as *const crate::Attribute) }
}
}
impl std::ops::DerefMut for $rust_type {
fn deref_mut(&mut self) -> &mut crate::Attribute {
unsafe { &mut *(self as *mut $rust_type as *mut crate::Attribute) }
}
}
}
}