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
/// Defines a wrapper type and implements the appropriate traits.
///
/// The basic syntax is
///
/// ```ignore
/// glib_wrapper! {
/// /// Documentation
/// pub struct $name($kind<$foreign>);
///
/// match fn {
/// $fn_name => /* a closure-like expression */,
/// ...
/// }
/// }
/// ```
///
/// This creates a wrapper named `$name` around the foreign type `$foreign`
/// of $kind (one of `Boxed`, `Object`) using expressions from the `match fn`
/// block to implement type-specific low-level operations. The expression
/// will be evaluated in `unsafe` context.
///
/// ### Boxed
///
/// ```ignore
/// glib_wrapper! {
/// /// Text buffer iterator
/// pub struct TextIter(Boxed<ffi::GtkTextIter>);
///
/// match fn {
/// copy => |ptr| ffi::gtk_text_iter_copy(ptr),
/// free => |ptr| ffi::gtk_text_iter_free(ptr),
/// }
/// }
/// ```
///
/// `copy`: `|*const $foreign| -> *mut $foreign` creates a copy of the value.
///
/// `free`: `|*mut $foreign|` frees the value.
///
/// ### Refcounted
///
/// ```ignore
/// glib_wrapper! {
/// /// Object holding timing information for a single frame.
/// pub struct FrameTimings(Refcounted<ffi::GdkFrameTimings>);
///
/// match fn {
/// ref => |ptr| ffi::gdk_frame_timings_ref(ptr),
/// unref => |ptr| ffi::gdk_frame_timings_unref(ptr),
/// }
/// }
/// ```
///
/// `ref`: `|*mut $foreign|` increases the refcount.
///
/// `unref`: `|*mut $foreign|` decreases the refcount.
///
/// ### Object
///
/// ```
/// glib_wrapper! {
/// /// Object representing an input device.
/// pub struct Device(Object<ffi::GdkDevice>);
///
/// match fn {
/// get_type => || ffi::gdk_device_get_type(),
/// }
/// }
/// ```
///
/// ```
/// glib_wrapper! {
/// /// A container with just one child.
/// pub struct Bin(Object<ffi::GtkBin>): Container, Widget, Buildable;
///
/// match fn {
/// get_type => || ffi::gtk_bin_get_type(),
/// }
/// }
/// ```
///
/// `get_type: || -> GType` returns the type identifier of the class.
) => ;
=> ;
=> ;
=> ;
}
/// A wrapper struct.