1
+ use lazy_static:: lazy_static;
1
2
use regex:: Regex ;
2
- use std:: path :: { Path , PathBuf } ;
3
+ use std:: fs :: File ;
3
4
use std:: io:: prelude:: * ;
4
5
use std:: io:: BufReader ;
5
- use std:: fs:: File ;
6
- use lazy_static:: lazy_static;
6
+ use std:: path:: { Path , PathBuf } ;
7
7
// TODO use clap
8
+ use cached:: proc_macro:: cached;
8
9
use docopt:: Docopt ;
10
+ use reqwest:: blocking:: Client ;
9
11
use serde:: Deserialize ;
10
12
use std:: ffi:: CString ;
11
- use cached:: proc_macro:: cached;
12
- use reqwest:: blocking:: Client ;
13
13
14
14
/// For libxml2 FFI.
15
15
use libc:: { c_char, c_int, c_uint, FILE } ;
@@ -32,7 +32,10 @@ extern "C" {
32
32
pub fn xmlInitGlobals ( ) ;
33
33
34
34
// xmlschemas
35
- pub fn xmlSchemaNewMemParserCtxt ( buffer : * const c_char , size : c_int ) -> * mut XmlSchemaParserCtxt ;
35
+ pub fn xmlSchemaNewMemParserCtxt (
36
+ buffer : * const c_char ,
37
+ size : c_int ,
38
+ ) -> * mut XmlSchemaParserCtxt ;
36
39
//pub fn xmlSchemaSetParserErrors();
37
40
pub fn xmlSchemaParse ( ctxt : * const XmlSchemaParserCtxt ) -> * mut XmlSchema ;
38
41
pub fn xmlSchemaFreeParserCtxt ( ctxt : * mut XmlSchemaParserCtxt ) ;
@@ -101,8 +104,8 @@ fn get_schema(url: String) -> XmlSchemaPtr {
101
104
let response = CLIENT . get ( url. as_str ( ) ) . send ( ) . unwrap ( ) . bytes ( ) . unwrap ( ) ;
102
105
103
106
unsafe {
104
- let schema_parser_ctxt = xmlSchemaNewMemParserCtxt ( response . as_ptr ( ) as * const c_char ,
105
- response. len ( ) as i32 ) ;
107
+ let schema_parser_ctxt =
108
+ xmlSchemaNewMemParserCtxt ( response . as_ptr ( ) as * const c_char , response. len ( ) as i32 ) ;
106
109
107
110
// Use default callbacks rather than overriding.
108
111
//xmlSchemaSetParserErrors();
@@ -137,9 +140,7 @@ fn validate(path_buf: PathBuf) {
137
140
// Note: the message is output after the validation messages.
138
141
eprintln ! ( "{path_str} fails to validate" ) ;
139
142
} else {
140
- eprintln ! (
141
- "{path_str} validation generated an internal error"
142
- ) ;
143
+ eprintln ! ( "{path_str} validation generated an internal error" ) ;
143
144
}
144
145
145
146
xmlSchemaFreeValidCtxt ( schema_valid_ctxt) ;
@@ -158,14 +159,18 @@ fn main() {
158
159
}
159
160
160
161
// No real point in using WalkParallel.
161
- for result in ignore:: Walk :: new ( & args. arg_dir ) {
162
- if let Ok ( entry) = result {
163
- let path = entry. path ( ) . to_owned ( ) ;
164
- if let Some ( extension) = path. extension ( ) {
165
- if extension. to_str ( ) . unwrap ( ) == extension_str {
166
- validate ( path) ;
162
+ rayon:: scope ( |scope| {
163
+ for result in ignore:: Walk :: new ( & args. arg_dir ) {
164
+ scope. spawn ( move |_| {
165
+ if let Ok ( entry) = result {
166
+ let path = entry. path ( ) . to_owned ( ) ;
167
+ if let Some ( extension) = path. extension ( ) {
168
+ if extension. to_str ( ) . unwrap ( ) == extension_str {
169
+ validate ( path) ;
170
+ }
171
+ }
167
172
}
168
- }
173
+ } ) ;
169
174
}
170
- }
175
+ } ) ;
171
176
}
0 commit comments