@@ -19,7 +19,9 @@ use std::io;
19
19
pub struct DebugStructGenerator ;
20
20
21
21
impl super :: Generator for DebugStructGenerator {
22
- fn write < W > ( & self , registry : & Registry , dest : & mut W ) -> io:: Result < ( ) > where W : io:: Write {
22
+ fn write < W > ( & self , registry : & Registry , dest : & mut W ) -> io:: Result < ( ) >
23
+ where W : io:: Write
24
+ {
23
25
try!( write_header ( dest) ) ;
24
26
try!( write_type_aliases ( registry, dest) ) ;
25
27
try!( write_enums ( registry, dest) ) ;
@@ -33,8 +35,11 @@ impl super::Generator for DebugStructGenerator {
33
35
34
36
/// Creates a `__gl_imports` module which contains all the external symbols that we need for the
35
37
/// bindings.
36
- fn write_header < W > ( dest : & mut W ) -> io:: Result < ( ) > where W : io:: Write {
37
- writeln ! ( dest, r#"
38
+ fn write_header < W > ( dest : & mut W ) -> io:: Result < ( ) >
39
+ where W : io:: Write
40
+ {
41
+ writeln ! ( dest,
42
+ r#"
38
43
mod __gl_imports {{
39
44
pub use std::mem;
40
45
pub use std::marker::Send;
@@ -46,8 +51,11 @@ fn write_header<W>(dest: &mut W) -> io::Result<()> where W: io::Write {
46
51
/// Creates a `types` module which contains all the type aliases.
47
52
///
48
53
/// See also `generators::gen_types`.
49
- fn write_type_aliases < W > ( registry : & Registry , dest : & mut W ) -> io:: Result < ( ) > where W : io:: Write {
50
- try!( writeln ! ( dest, r#"
54
+ fn write_type_aliases < W > ( registry : & Registry , dest : & mut W ) -> io:: Result < ( ) >
55
+ where W : io:: Write
56
+ {
57
+ try!( writeln ! ( dest,
58
+ r#"
51
59
pub mod types {{
52
60
#![allow(non_camel_case_types, non_snake_case, dead_code, missing_copy_implementations)]
53
61
"# ) ) ;
@@ -58,7 +66,9 @@ fn write_type_aliases<W>(registry: &Registry, dest: &mut W) -> io::Result<()> wh
58
66
}
59
67
60
68
/// Creates all the `<enum>` elements at the root of the bindings.
61
- fn write_enums < W > ( registry : & Registry , dest : & mut W ) -> io:: Result < ( ) > where W : io:: Write {
69
+ fn write_enums < W > ( registry : & Registry , dest : & mut W ) -> io:: Result < ( ) >
70
+ where W : io:: Write
71
+ {
62
72
for enm in & registry. enums {
63
73
try!( super :: gen_enum_item ( enm, "types::" , dest) ) ;
64
74
}
@@ -67,8 +77,11 @@ fn write_enums<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W:
67
77
}
68
78
69
79
/// Creates a `FnPtr` structure which contains the store for a single binding.
70
- fn write_fnptr_struct_def < W > ( dest : & mut W ) -> io:: Result < ( ) > where W : io:: Write {
71
- writeln ! ( dest, "
80
+ fn write_fnptr_struct_def < W > ( dest : & mut W ) -> io:: Result < ( ) >
81
+ where W : io:: Write
82
+ {
83
+ writeln ! ( dest,
84
+ "
72
85
#[allow(dead_code, missing_copy_implementations)]
73
86
#[derive(Clone)]
74
87
pub struct FnPtr {{
@@ -106,26 +119,29 @@ fn write_fnptr_struct_def<W>(dest: &mut W) -> io::Result<()> where W: io::Write
106
119
/// Creates a `panicking` module which contains one function per GL command.
107
120
///
108
121
/// These functions are the mocks that are called if the real function could not be loaded.
109
- fn write_panicking_fns < W > ( registry : & Registry , dest : & mut W ) -> io:: Result < ( ) > where W : io:: Write {
122
+ fn write_panicking_fns < W > ( registry : & Registry , dest : & mut W ) -> io:: Result < ( ) >
123
+ where W : io:: Write
124
+ {
110
125
writeln ! ( dest,
111
- "#[inline(never)]
126
+ "#[inline(never)]
112
127
fn missing_fn_panic() -> ! {{
113
128
panic!(\" {api} function was not loaded\" )
114
129
}}" ,
115
- api = registry. api
116
- )
130
+ api = registry. api)
117
131
}
118
132
119
133
/// Creates a structure which stores all the `FnPtr` of the bindings.
120
134
///
121
135
/// The name of the struct corresponds to the namespace.
122
- fn write_struct < W > ( registry : & Registry , dest : & mut W ) -> io:: Result < ( ) > where W : io:: Write {
123
- try!( writeln ! ( dest, "
136
+ fn write_struct < W > ( registry : & Registry , dest : & mut W ) -> io:: Result < ( ) >
137
+ where W : io:: Write
138
+ {
139
+ try!( writeln ! ( dest,
140
+ "
124
141
#[allow(non_camel_case_types, non_snake_case, dead_code)]
125
142
#[derive(Clone)]
126
143
pub struct {api} {{" ,
127
- api = super :: gen_struct_name( registry. api)
128
- ) ) ;
144
+ api = super :: gen_struct_name( registry. api) ) ) ;
129
145
130
146
for cmd in & registry. cmds {
131
147
if let Some ( v) = registry. aliases . get ( & cmd. proto . ident ) {
@@ -138,9 +154,11 @@ fn write_struct<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W:
138
154
}
139
155
140
156
/// Creates the `impl` of the structure created by `write_struct`.
141
- fn write_impl < W > ( registry : & Registry , dest : & mut W ) -> io:: Result < ( ) > where W : io:: Write {
157
+ fn write_impl < W > ( registry : & Registry , dest : & mut W ) -> io:: Result < ( ) >
158
+ where W : io:: Write
159
+ {
142
160
try!( writeln ! ( dest,
143
- "impl {api} {{
161
+ "impl {api} {{
144
162
/// Load each OpenGL symbol using a custom load function. This allows for the
145
163
/// use of functions like `glfwGetProcAddress` or `SDL_GL_GetProcAddress`.
146
164
///
@@ -167,8 +185,7 @@ fn write_impl<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: i
167
185
do_metaloadfn(&mut loadfn, symbol, symbols)
168
186
}};
169
187
{api} {{" ,
170
- api = super :: gen_struct_name( registry. api)
171
- ) ) ;
188
+ api = super :: gen_struct_name( registry. api) ) ) ;
172
189
173
190
for cmd in & registry. cmds {
174
191
try!( writeln ! ( dest,
@@ -187,53 +204,60 @@ fn write_impl<W>(registry: &Registry, dest: &mut W) -> io::Result<()> where W: i
187
204
}
188
205
189
206
try!( writeln ! ( dest,
190
- "}}
191
- }}"
192
- ) ) ;
207
+ "}}
208
+ }}" ) ) ;
193
209
194
210
for cmd in & registry. cmds {
195
211
let idents = super :: gen_parameters ( cmd, true , false ) ;
196
212
let typed_params = super :: gen_parameters ( cmd, false , true ) ;
197
213
let println = format ! ( "println!(\" [OpenGL] {}({})\" {});" ,
198
- cmd. proto. ident,
199
- ( 0 .. idents. len( ) ) . map( |_| "{:?}" . to_string( ) ) . collect:: <Vec <_>>( ) . join( ", " ) ,
200
- idents. iter( ) . zip( typed_params. iter( ) )
201
- . map( |( name, ty) | {
202
- if ty. contains( "GLDEBUGPROC" ) {
203
- format!( ", \" <callback>\" " )
204
- } else {
205
- format!( ", {}" , name)
206
- }
207
- } ) . collect:: <Vec <_>>( ) . concat( ) ) ;
214
+ cmd. proto. ident,
215
+ ( 0 ..idents. len( ) )
216
+ . map( |_| "{:?}" . to_string( ) )
217
+ . collect:: <Vec <_>>( )
218
+ . join( ", " ) ,
219
+ idents
220
+ . iter( )
221
+ . zip( typed_params. iter( ) )
222
+ . map( |( name, ty) | if ty. contains( "GLDEBUGPROC" ) {
223
+ format!( ", \" <callback>\" " )
224
+ } else {
225
+ format!( ", {}" , name)
226
+ } )
227
+ . collect:: <Vec <_>>( )
228
+ . concat( ) ) ;
208
229
209
230
try!( writeln ! ( dest,
210
- "#[allow(non_snake_case, unused_variables, dead_code)]
231
+ "#[allow(non_snake_case, unused_variables, dead_code)]
211
232
#[inline] pub unsafe fn {name}(&self, {params}) -> {return_suffix} {{ \
212
233
{println}
213
234
let r = __gl_imports::mem::transmute::<_, extern \" system\" fn({typed_params}) -> {return_suffix}>\
214
235
(self.{name}.f)({idents});
215
236
{print_err}
216
237
r
217
238
}}" ,
218
- name = cmd. proto. ident,
219
- params = super :: gen_parameters( cmd, true , true ) . join( ", " ) ,
220
- typed_params = typed_params. join( ", " ) ,
221
- return_suffix = cmd. proto. ty,
222
- idents = idents. join( ", " ) ,
223
- println = println,
224
- print_err = if cmd. proto. ident != "GetError" && registry. cmds. iter( ) . find( |cmd| cmd. proto. ident == "GetError" ) . is_some( ) {
225
- format!( r#"match __gl_imports::mem::transmute::<_, extern "system" fn() -> u32>
239
+ name = cmd. proto. ident,
240
+ params = super :: gen_parameters( cmd, true , true ) . join( ", " ) ,
241
+ typed_params = typed_params. join( ", " ) ,
242
+ return_suffix = cmd. proto. ty,
243
+ idents = idents. join( ", " ) ,
244
+ println = println,
245
+ print_err = if cmd. proto. ident != "GetError" &&
246
+ registry
247
+ . cmds
248
+ . iter( )
249
+ . find( |cmd| cmd. proto. ident == "GetError" )
250
+ . is_some( ) {
251
+ format!( r#"match __gl_imports::mem::transmute::<_, extern "system" fn() -> u32>
226
252
(self.GetError.f)() {{ 0 => (), r => println!("[OpenGL] ^ GL error triggered: {{}}", r) }}"# )
227
- } else {
228
- format!( "" )
229
- }
230
- ) )
253
+ } else {
254
+ format!( "" )
255
+ } ) )
231
256
}
232
257
233
258
writeln ! ( dest,
234
- "}}
259
+ "}}
235
260
236
261
unsafe impl __gl_imports::Send for {api} {{}}" ,
237
- api = super :: gen_struct_name( registry. api)
238
- )
262
+ api = super :: gen_struct_name( registry. api) )
239
263
}
0 commit comments