diff options
-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()); } |