diff options
author | Christian Poveda <christian.poveda@ferrous-systems.com> | 2022-08-16 11:24:06 -0500 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2022-08-18 18:08:37 +0200 |
commit | bc19e553da2e5c89470f413b1e07e4c9a5647b58 (patch) | |
tree | 9740c6b3cfe104615ac6cd1981067611b7869054 | |
parent | c5995bda24d628ddecda8bbe10db9b4415cc973a (diff) |
remove macro in favor of a method
-rw-r--r-- | src/lib.rs | 30 | ||||
-rw-r--r-- | tests/tests.rs | 4 |
2 files changed, 16 insertions, 18 deletions
@@ -33,19 +33,6 @@ mod log_stubs; #[macro_use] mod extra_assertions; -/// Print all the warning messages raised while generating the bindings in a build script. -/// -/// If you are using `bindgen` outside of a build script you should use [`Bindings::take_warnings`] -/// directly instead. -#[macro_export] -macro_rules! print_warnings { - ($bindings:expr) => { - for message in $bindings.take_warnings() { - println!("cargo:warning={}", message); - } - }; -} - // A macro to declare an internal module for which we *must* provide // documentation for. If we are building with the "testing_only_docs" feature, // then the module is declared public, and our `#![deny(missing_docs)]` pragma @@ -2599,10 +2586,21 @@ impl Bindings { } } - /// Take all the warning messages. + /// Emit all the warning messages raised while generating the bindings in a build script. + /// + /// If you are using `bindgen` outside of a build script you should use [`Bindings::warnings`] + /// and handle the messages accordingly instead. + #[inline] + pub fn emit_warnings(&self) { + for message in &self.warnings { + println!("cargo:warning={}", message); + } + } + + /// Return all the warning messages raised while generating the bindings. #[inline] - pub fn take_warnings(&mut self) -> impl Iterator<Item = String> + '_ { - self.warnings.drain(..) + pub fn warnings(&self) -> &[String] { + &self.warnings } } diff --git a/tests/tests.rs b/tests/tests.rs index 7b46df5e..71fc54be 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -678,11 +678,11 @@ fn allowlist_warnings() { "/tests/headers/allowlist_warnings.h" ); - let mut bindings = builder() + let bindings = builder() .header(header) .allowlist_function("doesnt_match_anything") .generate() .expect("unable to generate bindings"); - assert_eq!(1, bindings.take_warnings().count()); + assert_eq!(1, bindings.warnings().len()); } |