Files
tokio/src/lib.rs
T

121 lines
3.4 KiB
Rust
Raw Normal View History

//! A runtime for writing reliable, asynchronous, and slim applications.
2016-07-30 17:53:12 -07:00
//!
//! Tokio is an event-driven, non-blocking I/O platform for writing asynchronous
//! applications with the Rust programming language. At a high level, it
//! provides a few major components:
2017-12-05 16:55:25 +01:00
//!
//! * A multi threaded, work-stealing based task [scheduler][runtime].
2018-07-22 13:35:30 -07:00
//! * A [reactor] backed by the operating system's event queue (epoll, kqueue,
//! IOCP, etc...).
//! * Asynchronous [TCP and UDP][net] sockets.
2018-05-02 11:19:58 -07:00
//! * Asynchronous [filesystem][fs] operations.
2018-03-30 11:50:02 -07:00
//! * [Timer][timer] API for scheduling work in the future.
2016-09-02 11:07:52 -07:00
//!
2018-03-30 11:50:02 -07:00
//! Tokio is built using [futures] as the abstraction for managing the
//! complexity of asynchronous programming.
2016-09-02 11:07:52 -07:00
//!
//! Guide level documentation is found on the [website].
2016-09-02 11:07:52 -07:00
//!
//! [website]: https://tokio.rs/docs/getting-started/hello-world/
2018-07-22 13:35:30 -07:00
//! [futures]: http://docs.rs/futures/0.1
2017-01-11 09:14:50 -08:00
//!
2016-09-02 11:07:52 -07:00
//! # Examples
//!
//! A simple TCP echo server:
//!
//! ```no_run
2017-10-24 16:30:16 -07:00
//! extern crate tokio;
2016-09-02 11:07:52 -07:00
//!
//! use tokio::prelude::*;
//! use tokio::io::copy;
2017-10-24 16:30:16 -07:00
//! use tokio::net::TcpListener;
2016-09-02 11:07:52 -07:00
//!
//! fn main() {
2017-12-05 16:55:25 +01:00
//! // Bind the server's socket.
2017-01-10 10:02:15 -08:00
//! let addr = "127.0.0.1:12345".parse().unwrap();
//! let listener = TcpListener::bind(&addr)
2017-12-05 16:55:25 +01:00
//! .expect("unable to bind TCP listener");
2017-01-10 10:02:15 -08:00
//!
//! // Pull out a stream of sockets for incoming connections
//! let server = listener.incoming()
//! .map_err(|e| eprintln!("accept failed = {:?}", e))
//! .for_each(|sock| {
//! // Split up the reading and writing parts of the
//! // socket.
//! let (reader, writer) = sock.split();
//!
//! // A future that echos the data and returns how
//! // many bytes were copied...
//! let bytes_copied = copy(reader, writer);
//!
//! // ... after which we'll print what happened.
//! let handle_conn = bytes_copied.map(|amt| {
//! println!("wrote {:?} bytes", amt)
//! }).map_err(|err| {
//! eprintln!("IO error {:?}", err)
//! });
//!
//! // Spawn the future as a concurrent task.
//! tokio::spawn(handle_conn)
2017-01-10 10:02:15 -08:00
//! });
//!
//! // Start the Tokio runtime
//! tokio::run(server);
2016-09-02 11:07:52 -07:00
//! }
//! ```
2016-07-30 17:53:12 -07:00
2018-03-30 15:37:52 -07:00
#![doc(html_root_url = "https://docs.rs/tokio/0.1.5")]
#![deny(missing_docs, warnings, missing_debug_implementations)]
2018-09-26 10:10:47 -07:00
#![cfg_attr(feature = "async-await-preview", feature(
async_await,
await_macro,
futures_api,
))]
2016-07-30 17:53:12 -07:00
extern crate bytes;
2017-02-05 17:06:57 -08:00
#[macro_use]
2016-07-30 17:53:12 -07:00
extern crate futures;
extern crate mio;
2018-06-12 19:26:03 +02:00
extern crate tokio_current_thread;
2017-02-05 17:06:57 -08:00
extern crate tokio_io;
extern crate tokio_executor;
extern crate tokio_codec;
2018-05-02 11:19:58 -07:00
extern crate tokio_fs;
extern crate tokio_reactor;
extern crate tokio_threadpool;
2018-03-30 11:50:02 -07:00
extern crate tokio_timer;
extern crate tokio_tcp;
extern crate tokio_udp;
2016-07-30 17:53:12 -07:00
2018-09-26 10:10:47 -07:00
#[cfg(feature = "async-await-preview")]
extern crate tokio_async_await;
2018-08-16 06:26:10 +02:00
#[cfg(unix)]
extern crate tokio_uds;
pub mod clock;
pub mod codec;
pub mod executor;
2018-05-02 11:19:58 -07:00
pub mod fs;
pub mod io;
2016-09-02 11:07:52 -07:00
pub mod net;
pub mod prelude;
2016-09-02 11:07:52 -07:00
pub mod reactor;
pub mod runtime;
2018-03-30 11:50:02 -07:00
pub mod timer;
pub mod util;
pub use executor::spawn;
pub use runtime::run;
// ===== Experimental async/await support =====
2018-09-26 10:10:47 -07:00
#[cfg(feature = "async-await-preview")]
mod async_await;
#[cfg(feature = "async-await-preview")]
pub use async_await::{run_async, spawn_async};
#[cfg(feature = "async-await-preview")]
pub use tokio_async_await::await;