summaryrefslogtreecommitdiff
path: root/src/tokio_write.rs
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-03-19 12:18:05 -0400
committerGitHub <noreply@github.com>2019-03-19 12:18:05 -0400
commitfa3c35301aa44975776b96c85f200de8eb500c22 (patch)
tree76f8d5e6f42e1c306a40efd0b80dce18528952f4 /src/tokio_write.rs
parentc7d81fa9ff495986675c05e52e13acc9ffc85372 (diff)
Rename //src/ to //cli/ (#1962)
To better distinguish the deno_core crate from the executable deno, which will now be called "the cli" internally.
Diffstat (limited to 'src/tokio_write.rs')
-rw-r--r--src/tokio_write.rs62
1 files changed, 0 insertions, 62 deletions
diff --git a/src/tokio_write.rs b/src/tokio_write.rs
deleted file mode 100644
index 945de375d..000000000
--- a/src/tokio_write.rs
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-// TODO Submit this file upstream into tokio-io/src/io/write.rs
-use std::io;
-use std::mem;
-
-use futures::{Future, Poll};
-use tokio::io::AsyncWrite;
-
-/// A future used to write some data to a stream.
-///
-/// This is created by the [`write`] top-level method.
-///
-/// [`write`]: fn.write.html
-#[derive(Debug)]
-pub struct Write<A, T> {
- state: State<A, T>,
-}
-
-#[derive(Debug)]
-enum State<A, T> {
- Pending { a: A, buf: T },
- Empty,
-}
-
-/// Creates a future that will write some of the buffer `buf` to
-/// the stream `a` provided.
-///
-/// Any error which happens during writing will cause both the stream and the
-/// buffer to get destroyed.
-pub fn write<A, T>(a: A, buf: T) -> Write<A, T>
-where
- A: AsyncWrite,
- T: AsRef<[u8]>,
-{
- Write {
- state: State::Pending { a, buf },
- }
-}
-
-impl<A, T> Future for Write<A, T>
-where
- A: AsyncWrite,
- T: AsRef<[u8]>,
-{
- type Item = (A, T, usize);
- type Error = io::Error;
-
- fn poll(&mut self) -> Poll<(A, T, usize), io::Error> {
- let nwritten = match self.state {
- State::Pending {
- ref mut a,
- ref mut buf,
- } => try_ready!(a.poll_write(buf.as_ref())),
- State::Empty => panic!("poll a Read after it's done"),
- };
-
- match mem::replace(&mut self.state, State::Empty) {
- State::Pending { a, buf } => Ok((a, buf, nwritten).into()),
- State::Empty => panic!("invalid internal state"),
- }
- }
-}