Skip to content

Commit 77485e3

Browse files
committed
remove failure dependency
1 parent b70d354 commit 77485e3

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

foundationdb-gen/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ fdb-6_1 = [ ]
3636
fdb-6_2 = [ ]
3737

3838
[dependencies]
39-
failure = "0.1.6"
4039
xml-rs = "0.8.0"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extern crate foundationdb_gen;
22

33
fn main() {
4-
let code = foundationdb_gen::emit().expect("couldn't generate options.rs code!");
4+
let mut code = String::new();
5+
foundationdb_gen::emit(&mut code).expect("couldn't generate options.rs code!");
56
println!("{}", code);
67
}

foundationdb-gen/src/lib.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
extern crate xml;
2-
#[macro_use]
3-
extern crate failure;
4-
5-
type Result<T> = std::result::Result<T, failure::Error>;
62

73
use std::fmt;
8-
use std::fmt::Write;
94
use xml::attribute::OwnedAttribute;
105
use xml::reader::{EventReader, XmlEvent};
116

@@ -321,18 +316,18 @@ impl From<Vec<OwnedAttribute>> for FdbOption {
321316
}
322317
}
323318

324-
fn on_scope<I>(parser: &mut I) -> Result<Vec<FdbOption>>
319+
fn on_scope<I>(parser: &mut I) -> Vec<FdbOption>
325320
where
326321
I: Iterator<Item = xml::reader::Result<XmlEvent>>,
327322
{
328323
let mut options = Vec::new();
329324
for e in parser {
330-
let e = e?;
325+
let e = e.unwrap();
331326
match e {
332327
XmlEvent::StartElement {
333328
name, attributes, ..
334329
} => {
335-
ensure!(name.local_name == "Option", "unexpected token");
330+
assert_eq!(name.local_name, "Option", "unexpected token");
336331

337332
let option = FdbOption::from(attributes.clone());
338333
if !option.hidden {
@@ -341,14 +336,14 @@ where
341336
}
342337
XmlEvent::EndElement { name, .. } => {
343338
if name.local_name == "Scope" {
344-
return Ok(options);
339+
return options;
345340
}
346341
}
347342
_ => {}
348343
}
349344
}
350345

351-
bail!("unexpected end of token");
346+
panic!("unexpected end of token");
352347
}
353348

354349
#[cfg(all(not(feature = "embedded-fdb-include"), target_os = "linux"))]
@@ -372,7 +367,7 @@ const OPTIONS_DATA: &[u8] = include_bytes!("../include/610/fdb.options");
372367
#[cfg(all(feature = "embedded-fdb-include", feature = "fdb-6_2"))]
373368
const OPTIONS_DATA: &[u8] = include_bytes!("../include/620/fdb.options");
374369

375-
pub fn emit() -> Result<String> {
370+
pub fn emit(w: &mut impl fmt::Write) -> fmt::Result {
376371
let mut reader = OPTIONS_DATA;
377372
let parser = EventReader::new(&mut reader);
378373
let mut iter = parser.into_iter();
@@ -389,7 +384,7 @@ pub fn emit() -> Result<String> {
389384
.find(|attr| attr.name.local_name == "name")
390385
.unwrap();
391386

392-
let options = on_scope(&mut iter).unwrap();
387+
let options = on_scope(&mut iter);
393388
scopes.push(FdbScope {
394389
name: scope_name.value,
395390
options,
@@ -403,14 +398,13 @@ pub fn emit() -> Result<String> {
403398
}
404399
}
405400

406-
let mut w = String::new();
407401
writeln!(w, "use std::convert::TryFrom;")?;
408402
writeln!(w, "use crate::{{FdbError, FdbResult}};")?;
409403
writeln!(w, "use foundationdb_sys as fdb_sys;")?;
410404
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)?;
413407
}
414408

415-
Ok(w)
409+
Ok(())
416410
}

foundationdb/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use std::path::PathBuf;
88
fn main() {
99
let out_path = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR is undefined!"));
1010
let options_file = out_path.join("options.rs");
11-
let options = foundationdb_gen::emit().expect("couldn't emit options.rs code!");
11+
let mut options = String::new();
12+
foundationdb_gen::emit(&mut options).expect("couldn't emit options.rs code!");
1213

1314
File::create(options_file)
1415
.expect("couldn't create options.rs!")

0 commit comments

Comments
 (0)