1 #![deny(missing_docs, missing_debug_implementations, warnings)]
2 #![doc(html_root_url = "https://docs.rs/tokio-io/0.1.12")]
3 
4 //! Core I/O traits and combinators when working with Tokio.
5 //!
6 //! A description of the high-level I/O combinators can be [found online] in
7 //! addition to a description of the [low level details].
8 //!
9 //! [found online]: https://tokio.rs/docs/getting-started/core/
10 //! [low level details]: https://tokio.rs/docs/going-deeper-tokio/core-low-level/
11 
12 #[macro_use]
13 extern crate log;
14 
15 #[macro_use]
16 extern crate futures;
17 extern crate bytes;
18 
19 use std::io as std_io;
20 
21 use futures::{Future, Stream};
22 
23 /// A convenience typedef around a `Future` whose error component is `io::Error`
24 pub type IoFuture<T> = Box<Future<Item = T, Error = std_io::Error> + Send>;
25 
26 /// A convenience typedef around a `Stream` whose error component is `io::Error`
27 pub type IoStream<T> = Box<Stream<Item = T, Error = std_io::Error> + Send>;
28 
29 /// A convenience macro for working with `io::Result<T>` from the `Read` and
30 /// `Write` traits.
31 ///
32 /// This macro takes `io::Result<T>` as input, and returns `T` as the output. If
33 /// the input type is of the `Err` variant, then `Poll::NotReady` is returned if
34 /// it indicates `WouldBlock` or otherwise `Err` is returned.
35 #[macro_export]
36 macro_rules! try_nb {
37     ($e:expr) => {
38         match $e {
39             Ok(t) => t,
40             Err(ref e) if e.kind() == ::std::io::ErrorKind::WouldBlock => {
41                 return Ok(::futures::Async::NotReady);
42             }
43             Err(e) => return Err(e.into()),
44         }
45     };
46 }
47 
48 pub mod codec;
49 pub mod io;
50 
51 pub mod _tokio_codec;
52 mod allow_std;
53 mod async_read;
54 mod async_write;
55 mod framed;
56 mod framed_read;
57 mod framed_write;
58 mod length_delimited;
59 mod lines;
60 mod split;
61 mod window;
62 
63 pub use self::async_read::AsyncRead;
64 pub use self::async_write::AsyncWrite;
65 
_assert_objects()66 fn _assert_objects() {
67     fn _assert<T>() {}
68     _assert::<Box<AsyncRead>>();
69     _assert::<Box<AsyncWrite>>();
70 }
71