aboutsummaryrefslogtreecommitdiffstats
path: root/src/pipe.rs
diff options
context:
space:
mode:
authorequal-l2 <eng.equall2@gmail.com>2020-07-17 20:26:31 +0000
committerequal-l2 <eng.equall2@gmail.com>2020-07-21 16:53:04 +0000
commitdde31288bdfb00cf325ae1f669d5fc098cee98ea (patch)
tree28585f88d0ff0c29591ab8d4bbd38815b842f02b /src/pipe.rs
parentMerge pull request #331 from svenstaro/dependabot/cargo/select-0.5.0 (diff)
downloadminiserve-dde31288bdfb00cf325ae1f669d5fc098cee98ea.tar.gz
miniserve-dde31288bdfb00cf325ae1f669d5fc098cee98ea.zip
Update to actix 2 and futures 0.3
Diffstat (limited to '')
-rw-r--r--src/pipe.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/pipe.rs b/src/pipe.rs
index 09ca580..92f7019 100644
--- a/src/pipe.rs
+++ b/src/pipe.rs
@@ -1,7 +1,8 @@
//! Define an adapter to implement `std::io::Write` on `Sender<Bytes>`.
-use bytes::{Bytes, BytesMut};
-use futures::sink::{Sink, Wait};
-use futures::sync::mpsc::Sender;
+use actix_web::web::{Bytes, BytesMut};
+use futures::channel::mpsc::Sender;
+use futures::executor::block_on;
+use futures::sink::SinkExt;
use std::io::{Error, ErrorKind, Result, Write};
/// Adapter to implement the `std::io::Write` trait on a `Sender<Bytes>` from a futures channel.
@@ -10,15 +11,15 @@ use std::io::{Error, ErrorKind, Result, Write};
pub struct Pipe {
// Wrapping the sender in `Wait` makes it blocking, so we can implement blocking-style
// io::Write over the async-style Sender.
- dest: Wait<Sender<Bytes>>,
+ dest: Sender<std::result::Result<Bytes, ()>>,
bytes: BytesMut,
}
impl Pipe {
/// Wrap the given sender in a `Pipe`.
- pub fn new(destination: Sender<Bytes>) -> Self {
+ pub fn new(destination: Sender<std::result::Result<Bytes, ()>>) -> Self {
Pipe {
- dest: destination.wait(),
+ dest: destination,
bytes: BytesMut::new(),
}
}
@@ -28,7 +29,7 @@ impl Drop for Pipe {
fn drop(&mut self) {
// This is the correct thing to do, but is not super important since the `Sink`
// implementation of `Sender` just returns `Ok` without doing anything else.
- let _ = self.dest.close();
+ let _ = block_on(self.dest.close());
}
}
@@ -38,8 +39,7 @@ impl Write for Pipe {
self.bytes.extend_from_slice(buf);
// Then, take the buffer and send it in the channel.
- self.dest
- .send(self.bytes.take().into())
+ block_on(self.dest.send(Ok(self.bytes.split().into())))
.map_err(|e| Error::new(ErrorKind::UnexpectedEof, e))?;
// Return how much we sent - all of it.
@@ -47,8 +47,6 @@ impl Write for Pipe {
}
fn flush(&mut self) -> Result<()> {
- self.dest
- .flush()
- .map_err(|e| Error::new(ErrorKind::UnexpectedEof, e))
+ block_on(self.dest.flush()).map_err(|e| Error::new(ErrorKind::UnexpectedEof, e))
}
}