Skip to content

Commit aadd44f

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

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
@@ -122,7 +122,7 @@ pub fn builder() -> Builder {
122122
}
123123

124124
/// Construct a new [`Builder`](./struct.Builder.html) from command line flags.
125-
pub fn builder_from_flags<I>(args: I) -> Result<Builder, io::Error>
125+
pub fn builder_from_flags<I>(args: I) -> Result<(Builder, Option<Box<io::Write>>), io::Error>
126126
where I: Iterator<Item=String>
127127
{
128128
let matches = App::new("bindgen")
@@ -343,15 +343,14 @@ pub fn builder_from_flags<I>(args: I) -> Result<Builder, io::Error>
343343
}
344344
}
345345

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

354-
Ok(builder)
353+
Ok((builder, Some(output)))
355354
}
356355

357356
impl Builder {

0 commit comments

Comments
 (0)