Skip to content

Commit bc19e55

Browse files
pvdrzemilio
authored andcommitted
remove macro in favor of a method
1 parent c5995bd commit bc19e55

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/lib.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,6 @@ mod log_stubs;
3333
#[macro_use]
3434
mod extra_assertions;
3535

36-
/// Print all the warning messages raised while generating the bindings in a build script.
37-
///
38-
/// If you are using `bindgen` outside of a build script you should use [`Bindings::take_warnings`]
39-
/// directly instead.
40-
#[macro_export]
41-
macro_rules! print_warnings {
42-
($bindings:expr) => {
43-
for message in $bindings.take_warnings() {
44-
println!("cargo:warning={}", message);
45-
}
46-
};
47-
}
48-
4936
// A macro to declare an internal module for which we *must* provide
5037
// documentation for. If we are building with the "testing_only_docs" feature,
5138
// then the module is declared public, and our `#![deny(missing_docs)]` pragma
@@ -2599,10 +2586,21 @@ impl Bindings {
25992586
}
26002587
}
26012588

2602-
/// Take all the warning messages.
2589+
/// Emit all the warning messages raised while generating the bindings in a build script.
2590+
///
2591+
/// If you are using `bindgen` outside of a build script you should use [`Bindings::warnings`]
2592+
/// and handle the messages accordingly instead.
2593+
#[inline]
2594+
pub fn emit_warnings(&self) {
2595+
for message in &self.warnings {
2596+
println!("cargo:warning={}", message);
2597+
}
2598+
}
2599+
2600+
/// Return all the warning messages raised while generating the bindings.
26032601
#[inline]
2604-
pub fn take_warnings(&mut self) -> impl Iterator<Item = String> + '_ {
2605-
self.warnings.drain(..)
2602+
pub fn warnings(&self) -> &[String] {
2603+
&self.warnings
26062604
}
26072605
}
26082606

tests/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,11 @@ fn allowlist_warnings() {
678678
"/tests/headers/allowlist_warnings.h"
679679
);
680680

681-
let mut bindings = builder()
681+
let bindings = builder()
682682
.header(header)
683683
.allowlist_function("doesnt_match_anything")
684684
.generate()
685685
.expect("unable to generate bindings");
686686

687-
assert_eq!(1, bindings.take_warnings().count());
687+
assert_eq!(1, bindings.warnings().len());
688688
}

0 commit comments

Comments
 (0)