1
1
extern crate xml;
2
- #[ macro_use]
3
- extern crate failure;
4
-
5
- type Result < T > = std:: result:: Result < T , failure:: Error > ;
6
2
7
3
use std:: fmt;
8
- use std:: fmt:: Write ;
9
4
use xml:: attribute:: OwnedAttribute ;
10
5
use xml:: reader:: { EventReader , XmlEvent } ;
11
6
@@ -321,18 +316,18 @@ impl From<Vec<OwnedAttribute>> for FdbOption {
321
316
}
322
317
}
323
318
324
- fn on_scope < I > ( parser : & mut I ) -> Result < Vec < FdbOption > >
319
+ fn on_scope < I > ( parser : & mut I ) -> Vec < FdbOption >
325
320
where
326
321
I : Iterator < Item = xml:: reader:: Result < XmlEvent > > ,
327
322
{
328
323
let mut options = Vec :: new ( ) ;
329
324
for e in parser {
330
- let e = e? ;
325
+ let e = e. unwrap ( ) ;
331
326
match e {
332
327
XmlEvent :: StartElement {
333
328
name, attributes, ..
334
329
} => {
335
- ensure ! ( name. local_name == "Option" , "unexpected token" ) ;
330
+ assert_eq ! ( name. local_name, "Option" , "unexpected token" ) ;
336
331
337
332
let option = FdbOption :: from ( attributes. clone ( ) ) ;
338
333
if !option. hidden {
@@ -341,14 +336,14 @@ where
341
336
}
342
337
XmlEvent :: EndElement { name, .. } => {
343
338
if name. local_name == "Scope" {
344
- return Ok ( options) ;
339
+ return options;
345
340
}
346
341
}
347
342
_ => { }
348
343
}
349
344
}
350
345
351
- bail ! ( "unexpected end of token" ) ;
346
+ panic ! ( "unexpected end of token" ) ;
352
347
}
353
348
354
349
#[ cfg( all( not( feature = "embedded-fdb-include" ) , target_os = "linux" ) ) ]
@@ -372,7 +367,7 @@ const OPTIONS_DATA: &[u8] = include_bytes!("../include/610/fdb.options");
372
367
#[ cfg( all( feature = "embedded-fdb-include" , feature = "fdb-6_2" ) ) ]
373
368
const OPTIONS_DATA : & [ u8 ] = include_bytes ! ( "../include/620/fdb.options" ) ;
374
369
375
- pub fn emit ( ) -> Result < String > {
370
+ pub fn emit ( w : & mut impl fmt :: Write ) -> fmt :: Result {
376
371
let mut reader = OPTIONS_DATA ;
377
372
let parser = EventReader :: new ( & mut reader) ;
378
373
let mut iter = parser. into_iter ( ) ;
@@ -389,7 +384,7 @@ pub fn emit() -> Result<String> {
389
384
. find ( |attr| attr. name . local_name == "name" )
390
385
. unwrap ( ) ;
391
386
392
- let options = on_scope ( & mut iter) . unwrap ( ) ;
387
+ let options = on_scope ( & mut iter) ;
393
388
scopes. push ( FdbScope {
394
389
name : scope_name. value ,
395
390
options,
@@ -403,14 +398,13 @@ pub fn emit() -> Result<String> {
403
398
}
404
399
}
405
400
406
- let mut w = String :: new ( ) ;
407
401
writeln ! ( w, "use std::convert::TryFrom;" ) ?;
408
402
writeln ! ( w, "use crate::{{FdbError, FdbResult}};" ) ?;
409
403
writeln ! ( w, "use foundationdb_sys as fdb_sys;" ) ?;
410
404
for scope in scopes. iter ( ) {
411
- scope. gen_ty ( & mut w) ?;
412
- scope. gen_impl ( & mut w) ?;
405
+ scope. gen_ty ( w) ?;
406
+ scope. gen_impl ( w) ?;
413
407
}
414
408
415
- Ok ( w )
409
+ Ok ( ( ) )
416
410
}
0 commit comments