Skip to content

Commit 11f91c8

Browse files
committed
Result<(Builder, Option<Box<io::Write>>), io::Error>
- just another progress check-in - the Option is probably unnecessary
1 parent ef5385b commit 11f91c8

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/bin/bindgen.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,16 @@ pub fn main() {
6666
}
6767
}
6868

69-
if let Ok(builder) = bindgen::builder_from_flags(env::args()) {
69+
if let Ok((builder, Some(output))) = bindgen::builder_from_flags(env::args()) {
7070
//println!("{:#?}", builder);
7171

7272
let bindings = builder.generate()
7373
.expect("Unable to generate bindings");
7474

75-
println!("{}", bindings.to_string());
75+
if let Err(error) = bindings.write(output) {
76+
println!("{:#?}", error);
77+
std::process::exit(1);
78+
}
7679
}
7780

7881
/*

src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub fn builder() -> Builder {
125125
}
126126

127127
/// Construct a new [`Builder`](./struct.Builder.html) from command line flags.
128-
pub fn builder_from_flags<I>(args: I) -> Result<Builder, io::Error>
128+
pub fn builder_from_flags<I>(args: I) -> Result<(Builder, Option<Box<io::Write>>), io::Error>
129129
where I: Iterator<Item=String>
130130
{
131131
let matches = App::new("bindgen")
@@ -346,15 +346,14 @@ pub fn builder_from_flags<I>(args: I) -> Result<Builder, io::Error>
346346
}
347347
}
348348

349-
// FIXME: hrrrmmm
350-
let _output = if let Some(path) = matches.value_of("output") {
349+
let output = if let Some(path) = matches.value_of("output") {
351350
let file = try!(File::create(path));
352351
Box::new(io::BufWriter::new(file)) as Box<io::Write>
353352
} else {
354353
Box::new(io::BufWriter::new(io::stdout())) as Box<io::Write>
355354
};
356355

357-
Ok(builder)
356+
Ok((builder, Some(output)))
358357
}
359358

360359
impl Builder {

0 commit comments

Comments
 (0)