Skip to content

Commit b1752f4

Browse files
committed
Implement async reader
1 parent 658bc0c commit b1752f4

File tree

3 files changed

+719
-0
lines changed

3 files changed

+719
-0
lines changed

Cargo.toml

+17
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ document-features = { version = "0.2", optional = true }
1616
encoding_rs = { version = "0.8", optional = true }
1717
serde = { version = "1.0", optional = true }
1818
memchr = "2.5"
19+
tokio = { version = "1.19", optional = true, default-features = false, features = ["io-util"] }
20+
async-recursion = { version = "1.0", optional = true }
1921

2022
[dev-dependencies]
2123
criterion = "0.3"
2224
pretty_assertions = "1.2"
2325
regex = "1"
2426
serde = { version = "1.0", features = ["derive"] }
2527
serde-value = "0.7"
28+
tokio = { version = "1.20", default-features = false, features = ["macros", "rt-multi-thread"] }
29+
tokio-test = "0.4"
2630

2731
[lib]
2832
bench = false
@@ -101,6 +105,19 @@ serialize = ["serde"]
101105
## Enables support for recognizing all [HTML 5 entities](https://dev.w3.org/html5/html-author/charref)
102106
escape-html = []
103107

108+
## Enables support for asynchronous reading from `tokio`'s IO-Traits.
109+
##
110+
## This can be used for example with `Reader::from_async_reader(read)` where `read`
111+
## is some type implementing `tokio::io::AsyncBufRead`.
112+
async = ["tokio", "async-recursion"]
113+
114+
## Enables support for asynchronous reading from files using `tokio`. This feature
115+
## also automatically enables the `async` feature as well.
116+
##
117+
## This can be used for example with `Reader::from_file_async(path)` where `path`
118+
## is a file path.
119+
async-fs = ["async", "tokio/fs"]
120+
104121
[package.metadata.docs.rs]
105122
all-features = true
106123

src/reader.rs

+4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ use crate::name::{LocalName, NamespaceResolver, QName, ResolveResult};
1313

1414
use memchr;
1515

16+
#[cfg(feature = "async")]
17+
mod async_reader;
1618
mod io_reader;
1719
mod slice_reader;
1820

21+
#[cfg(feature = "async")]
22+
pub use self::async_reader::AsyncReader;
1923
pub use self::io_reader::IoReader;
2024
pub use self::slice_reader::SliceReader;
2125

0 commit comments

Comments
 (0)