Skip to content

Commit

Permalink
Implement async reader
Browse files Browse the repository at this point in the history
  • Loading branch information
999eagle committed Jul 15, 2022
1 parent 658bc0c commit 1049526
Show file tree
Hide file tree
Showing 4 changed files with 721 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ document-features = { version = "0.2", optional = true }
encoding_rs = { version = "0.8", optional = true }
serde = { version = "1.0", optional = true }
memchr = "2.5"
tokio = { version = "1.19", optional = true, default-features = false, features = ["io-util"] }
async-recursion = { version = "1.0", optional = true }

[dev-dependencies]
criterion = "0.3"
pretty_assertions = "1.2"
regex = "1"
serde = { version = "1.0", features = ["derive"] }
serde-value = "0.7"
tokio = { version = "1.20", default-features = false, features = ["macros", "rt-multi-thread"] }
tokio-test = "0.4"

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

## Enables support for asynchronous reading from `tokio`'s IO-Traits.
##
## This can be used for example with `Reader::from_async_reader(read)` where `read`
## is some type implementing `tokio::io::AsyncBufRead`.
async = ["tokio", "async-recursion"]

## Enables support for asynchronous reading from files using `tokio`. This feature
## also automatically enables the `async` feature as well.
##
## This can be used for example with `Reader::from_file_async(path)` where `path`
## is a file path.
async-fs = ["async", "tokio/fs"]

[package.metadata.docs.rs]
all-features = true

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,7 @@ mod writer;
#[cfg(feature = "serialize")]
pub use crate::errors::serialize::DeError;
pub use crate::errors::{Error, Result};
#[cfg(feature = "async")]
pub use crate::reader::AsyncReader;
pub use crate::reader::{Decoder, IoReader, Reader, SliceReader};
pub use crate::writer::{ElementWriter, Writer};
4 changes: 4 additions & 0 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ use crate::name::{LocalName, NamespaceResolver, QName, ResolveResult};

use memchr;

#[cfg(feature = "async")]
mod async_reader;
mod io_reader;
mod slice_reader;

#[cfg(feature = "async")]
pub use self::async_reader::AsyncReader;
pub use self::io_reader::IoReader;
pub use self::slice_reader::SliceReader;

Expand Down

0 comments on commit 1049526

Please sign in to comment.