Add Upload::into_async_read with blocking
This commit is contained in:
parent
e645e9d999
commit
45dc3d6d09
|
@ -14,9 +14,10 @@ categories = ["network-programming", "asynchronous"]
|
|||
readme = "README.md"
|
||||
|
||||
[features]
|
||||
default = ["apollo_tracing", "bson", "chrono", "chrono-tz", "log", "multipart", "tracing", "url"]
|
||||
default = ["apollo_tracing", "bson", "chrono", "chrono-tz", "log", "multipart", "tracing", "url", "unblock"]
|
||||
apollo_tracing = ["chrono"]
|
||||
multipart = ["multer", "bytes", "tempfile"]
|
||||
unblock = ["blocking"]
|
||||
# Used for doc(cfg())
|
||||
nightly = []
|
||||
|
||||
|
@ -50,6 +51,7 @@ url = { version = "2.1.1", optional = true }
|
|||
bytes = { version = "0.5.4", optional = true }
|
||||
multer = { version = "1.2.2", optional = true }
|
||||
tempfile = { version = "3.1.0", optional = true }
|
||||
blocking = { version = "1.0.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
async-std = { version = "1.5.0", features = ["attributes"] }
|
||||
|
|
|
@ -100,7 +100,8 @@
|
|||
//! extension](extensions/struct.ApolloTracing.html).
|
||||
//! - `log`: Enable the [logger extension](extensions/struct.Logger.html).
|
||||
//! - `tracing`: Enable the [tracing extension](extensions/struct.Tracing.html).
|
||||
//! - `multipart`: Support [sending files over HTTP multipart](http/fn.receive_multipart.html).
|
||||
//! - `multipart`: Support [sending files over HTTP multipart](http/fn.receive_body.html).
|
||||
//! - `unblock`: Support [asynchronous reader for Upload](http/struct.Upload.html)
|
||||
//! - `bson`: Integrate with the [`bson` crate](https://crates.io/crates/bson).
|
||||
//! - `chrono`: Integrate with the [`chrono` crate](https://crates.io/crates/chrono).
|
||||
//! - `chrono-tz`: Integrate with the [`chrono-tz` crate](https://crates.io/crates/chrono-tz).
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use crate::parser::types::UploadValue;
|
||||
use crate::{registry, InputValueError, InputValueResult, InputValueType, Type, Value};
|
||||
use blocking::Unblock;
|
||||
use futures::AsyncRead;
|
||||
use std::borrow::Cow;
|
||||
use std::io::Read;
|
||||
|
||||
|
@ -66,6 +68,13 @@ impl Upload {
|
|||
pub fn into_read(self) -> impl Read + Sync + Send + 'static {
|
||||
self.0.content
|
||||
}
|
||||
|
||||
#[cfg(feature = "unblock")]
|
||||
#[cfg_attr(feature = "nightly", doc(cfg(feature = "unblock")))]
|
||||
/// Convert to a `AsyncRead`.
|
||||
pub fn into_async_read(self) -> impl AsyncRead + Sync + Send + 'static {
|
||||
Unblock::new(self.0.content)
|
||||
}
|
||||
}
|
||||
|
||||
impl Type for Upload {
|
||||
|
|
Loading…
Reference in New Issue
Block a user