From 1217d2d51017dda6bce1cf8875d75fcad41235e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 3 Apr 2017 12:45:39 +0200 Subject: [PATCH] options: Allow configuring the generation of constructors. --- src/options.rs | 5 ++-- tests/expectations/tests/gen-constructors.rs | 29 ++++++++++++++++++++ tests/headers/gen-constructors.hpp | 6 ++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 tests/expectations/tests/gen-constructors.rs create mode 100644 tests/headers/gen-constructors.hpp diff --git a/src/options.rs b/src/options.rs index 15146b398a..d06ff4ab98 100644 --- a/src/options.rs +++ b/src/options.rs @@ -111,8 +111,8 @@ pub fn builder_from_flags Arg::with_name("generate") .long("generate") .help("Generate a given kind of items, split by commas. \ - Valid values are \"functions\",\"types\", \"vars\" and \ - \"methods\".") + Valid values are \"functions\",\"types\", \"vars\", \ + \"methods\" and \"constructors\".") .takes_value(true), Arg::with_name("ignore-methods") .long("ignore-methods") @@ -268,6 +268,7 @@ pub fn builder_from_flags "types" => config.types = true, "vars" => config.vars = true, "methods" => config.methods = true, + "constructors" => config.constructors = true, _ => { return Err(Error::new(ErrorKind::Other, "Unknown generate item")); diff --git a/tests/expectations/tests/gen-constructors.rs b/tests/expectations/tests/gen-constructors.rs new file mode 100644 index 0000000000..2899e266f0 --- /dev/null +++ b/tests/expectations/tests/gen-constructors.rs @@ -0,0 +1,29 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct Foo { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_Foo() { + assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); +} +impl Clone for Foo { + fn clone(&self) -> Self { *self } +} +impl Foo { + #[inline] + pub unsafe fn new(a: ::std::os::raw::c_int) -> Self { + let mut __bindgen_tmp = ::std::mem::uninitialized(); + Foo_Foo(&mut __bindgen_tmp, a); + __bindgen_tmp + } +} diff --git a/tests/headers/gen-constructors.hpp b/tests/headers/gen-constructors.hpp new file mode 100644 index 0000000000..c7d833d50b --- /dev/null +++ b/tests/headers/gen-constructors.hpp @@ -0,0 +1,6 @@ +// bindgen-flags: --generate types,constructors + +class Foo { + public: + Foo(int a); +};