Skip to content

Commit 7484d4d

Browse files
committed
Rip out all the async stuff.
1 parent 27fd621 commit 7484d4d

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

Cargo.lock

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ ignore = "*"
1010
regex = "*"
1111
lazy_static = "*"
1212
clap = "*"
13-
reqwest = "*"
13+
reqwest = { version = "*", features = ["blocking"] }
1414
dirs = "*"
1515
serde = "*"
1616
docopt = "*"
17-
cached = { version = "*", features = ["async_tokio_rt_multi_thread"] }
18-
tokio = { version = "1", features = ["rt", "rt-multi-thread", "fs"] }
17+
cached = "*"

src/main.rs

+17-22
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use regex::Regex;
22
use std::path::{Path, PathBuf};
3-
use tokio::io::{BufReader, AsyncBufReadExt};
4-
use tokio::task;
5-
use tokio::fs::File;
6-
use tokio::runtime::Handle;
3+
use std::io::prelude::*;
4+
use std::io::BufReader;
5+
use std::fs::File;
76
use lazy_static::lazy_static;
87
// TODO use clap
98
use docopt::Docopt;
109
use serde::Deserialize;
1110
use std::ffi::CString;
1211
use cached::proc_macro::cached;
12+
use reqwest::blocking::Client;
1313

1414
/// For libxml2 FFI.
1515
use libc::{c_char, c_int, c_uint, FILE};
@@ -70,16 +70,16 @@ struct Args {
7070

7171
/// Return the first Schema URL found, if any.
7272
/// Panic on any I/O error.
73-
async fn extract_schema_url(path: &Path) -> Option<String> {
73+
fn extract_schema_url(path: &Path) -> Option<String> {
7474
lazy_static! {
7575
static ref RE: Regex = Regex::new(r#"xsi:schemaLocation="\S+\s+(.+?)""#)
7676
.expect("failed to compile schemaLocation regex");
7777
}
7878

79-
let file = File::open(path).await.unwrap();
80-
let mut lines = BufReader::new(file).lines();
81-
while let Some(line) = lines.next_line().await.unwrap() {
82-
if let Some(caps) = RE.captures(&line) {
79+
let file = File::open(path).unwrap();
80+
let reader = BufReader::new(file);
81+
for line in reader.lines() {
82+
if let Some(caps) = RE.captures(&line.unwrap()) {
8383
return Some(caps[1].to_owned());
8484
}
8585
}
@@ -90,15 +90,15 @@ async fn extract_schema_url(path: &Path) -> Option<String> {
9090
///
9191
/// Panics on I/O error.
9292
#[cached(sync_writes = true)]
93-
async fn get_schema(url: String) -> XmlSchemaPtr {
93+
fn get_schema(url: String) -> XmlSchemaPtr {
9494
lazy_static! {
95-
static ref CLIENT: reqwest::Client = reqwest::Client::new();
95+
static ref CLIENT: Client = Client::new();
9696
}
9797

9898
// DEBUG to show that download happens only once.
9999
println!("Downloading now {url}...");
100100

101-
let response = CLIENT.get(url.as_str()).send().await.unwrap().bytes().await.unwrap();
101+
let response = CLIENT.get(url.as_str()).send().unwrap().bytes().unwrap();
102102

103103
unsafe {
104104
let schema_parser_ctxt = xmlSchemaNewMemParserCtxt(response.as_ptr() as *const c_char,
@@ -115,9 +115,9 @@ async fn get_schema(url: String) -> XmlSchemaPtr {
115115
}
116116

117117
/// Copy the behavior of [`xmllint`](https://github.com/GNOME/libxml2/blob/master/xmllint.c)
118-
async fn validate(path_buf: PathBuf) {
119-
let url = extract_schema_url(path_buf.as_path()).await.unwrap();
120-
let schema = get_schema(url).await;
118+
fn validate(path_buf: PathBuf) {
119+
let url = extract_schema_url(path_buf.as_path()).unwrap();
120+
let schema = get_schema(url);
121121

122122
let path_str = path_buf.to_str().unwrap();
123123
let c_path = CString::new(path_str).unwrap();
@@ -146,8 +146,7 @@ async fn validate(path_buf: PathBuf) {
146146
}
147147
}
148148

149-
#[tokio::main]
150-
async fn main() {
149+
fn main() {
151150
let args: Args = Docopt::new(USAGE)
152151
.and_then(|d| d.deserialize())
153152
.unwrap_or_else(|e| e.exit());
@@ -164,11 +163,7 @@ async fn main() {
164163
let path = entry.path().to_owned();
165164
if let Some(extension) = path.extension() {
166165
if extension.to_str().unwrap() == extension_str {
167-
task::block_in_place(move || {
168-
Handle::current().block_on(async move {
169-
validate(path).await;
170-
})
171-
})
166+
validate(path);
172167
}
173168
}
174169
}

0 commit comments

Comments
 (0)