windows_bindgen/
warnings.rs1use super::*;
2use std::sync::RwLock;
3
4#[derive(Default)]
5pub(crate) struct WarningBuilder(RwLock<Vec<String>>);
6
7impl WarningBuilder {
8 pub fn build(self) -> Warnings {
9 Warnings(self.0.write().unwrap().split_off(0))
10 }
11
12 pub fn add(&self, message: String) {
13 self.0.write().unwrap().push(message);
14 }
15
16 pub fn skip_method(&self, method: MethodDef, dependencies: &TypeMap, config: &Config) {
17 let mut message = String::new();
18 writeln!(
19 &mut message,
20 "skipping `{}.{}` due to missing dependencies:",
21 method.parent().type_name(),
22 method.name()
23 )
24 .unwrap();
25
26 for tn in dependencies.keys() {
27 if !config.types.contains_key(tn) && config.references.contains(*tn).is_none() {
28 writeln!(&mut message, " {tn}").unwrap();
29 }
30 }
31
32 self.add(message);
33 }
34}
35
36#[derive(Debug)]
38pub struct Warnings(Vec<String>);
39
40impl Warnings {
41 #[track_caller]
43 pub fn unwrap(&self) {
44 if !self.is_empty() {
45 panic!("{self}");
46 }
47 }
48}
49
50impl std::fmt::Display for Warnings {
51 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52 for message in &self.0 {
53 write!(f, "{message}")?;
54 }
55 Ok(())
56 }
57}
58
59impl std::ops::Deref for Warnings {
60 type Target = Vec<String>;
61
62 fn deref(&self) -> &Self::Target {
63 &self.0
64 }
65}