1
1
use crate :: gen:: out:: OutFile ;
2
+ use crate :: syntax:: IncludeKind ;
2
3
use std:: fmt:: { self , Display } ;
3
4
4
5
/// The complete contents of the "rust/cxx.h" header.
@@ -48,9 +49,15 @@ fn find_line(mut offset: usize, line: &str) -> Option<usize> {
48
49
}
49
50
}
50
51
52
+ #[ derive( PartialEq ) ]
53
+ pub struct Include {
54
+ pub path : String ,
55
+ pub kind : IncludeKind ,
56
+ }
57
+
51
58
#[ derive( Default , PartialEq ) ]
52
59
pub struct Includes {
53
- custom : Vec < String > ,
60
+ custom : Vec < Include > ,
54
61
pub array : bool ,
55
62
pub cstddef : bool ,
56
63
pub cstdint : bool ,
@@ -70,24 +77,30 @@ impl Includes {
70
77
Includes :: default ( )
71
78
}
72
79
73
- pub fn insert ( & mut self , include : impl AsRef < str > ) {
74
- self . custom . push ( include. as_ref ( ) . to_owned ( ) ) ;
80
+ pub fn insert ( & mut self , include : Include ) {
81
+ self . custom . push ( include) ;
75
82
}
76
83
}
77
84
78
- impl Extend < String > for Includes {
79
- fn extend < I : IntoIterator < Item = String > > ( & mut self , iter : I ) {
80
- self . custom . extend ( iter) ;
85
+ impl < ' a > Extend < & ' a String > for Includes {
86
+ fn extend < I : IntoIterator < Item = & ' a String > > ( & mut self , iter : I ) {
87
+ self . custom . extend ( iter. into_iter ( ) . map ( |path| Include {
88
+ path : path. clone ( ) ,
89
+ kind : IncludeKind :: Quoted ,
90
+ } ) ) ;
81
91
}
82
92
}
83
93
84
94
impl Display for Includes {
85
95
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
86
96
for include in & self . custom {
87
- if include. starts_with ( '<' ) && include. ends_with ( '>' ) {
88
- writeln ! ( f, "#include {}" , include) ?;
89
- } else {
90
- writeln ! ( f, "#include \" {}\" " , include. escape_default( ) ) ?;
97
+ match include. kind {
98
+ IncludeKind :: Quoted => {
99
+ writeln ! ( f, "#include \" {}\" " , include. path. escape_default( ) ) ?;
100
+ }
101
+ IncludeKind :: Bracketed => {
102
+ writeln ! ( f, "#include <{}>" , include. path) ?;
103
+ }
91
104
}
92
105
}
93
106
if self . array {
0 commit comments