summaryrefslogtreecommitdiffstats
path: root/examples/hello_world.rs
diff options
context:
space:
mode:
authorEliza Weisman <eliza@buoyant.io>2019-03-22 15:25:42 -0700
committerGitHub <noreply@github.com>2019-03-22 15:25:42 -0700
commit30330da11a56dfdd11bdbef50dba073a9edc36b2 (patch)
treebf4e8e90293a3c75a2bf5281572e1c01eceab3cb /examples/hello_world.rs
parent6e4945025cdc6f2b71d9b30aaa23c5517cca1504 (diff)
chore: Fix examples not working with `cargo run` (#998)
* chore: Fix examples not working with `cargo run` ## Motivation PR #991 moved the `tokio` crate to its own subdirectory, but did not move the `examples` directory into `tokio/examples`. While attempting to use the examples for testing another change, I noticed that #991 had broken the ability to use `cargo run`, as the examples were no longer considered part of a crate that cargo was aware of: ``` tokio on master [$] via 🦀v1.33.0 at ☸️ aks-eliza-dev ➜ cargo run --example chat error: no example target named `chat` Did you mean `echo`? ``` ## Solution This branch moves the examples into the `tokio` directory, so cargo is now once again aware of them: ``` tokio on eliza/fix-examples [$] via 🦀v1.33.0 at ☸️ aks-eliza-dev ➜ cargo run --example chat Compiling tokio-executor v0.1.7 (/Users/eliza/Code/tokio/tokio-executor) Compiling tokio-reactor v0.1.9 Compiling tokio-threadpool v0.1.13 Compiling tokio-current-thread v0.1.6 Compiling tokio-timer v0.2.10 Compiling tokio-uds v0.2.5 Compiling tokio-udp v0.1.3 Compiling tokio-tcp v0.1.3 Compiling tokio-fs v0.1.6 Compiling tokio v0.1.18 (/Users/eliza/Code/tokio/tokio) Finished dev [unoptimized + debuginfo] target(s) in 7.04s Running `target/debug/examples/chat` server running on localhost:6142 ``` Signed-off-by: Eliza Weisman <eliza@buoyant.io> Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Diffstat (limited to 'examples/hello_world.rs')
-rw-r--r--examples/hello_world.rs58
1 files changed, 0 insertions, 58 deletions
diff --git a/examples/hello_world.rs b/examples/hello_world.rs
deleted file mode 100644
index c8276269..00000000
--- a/examples/hello_world.rs
+++ /dev/null
@@ -1,58 +0,0 @@
-//! Hello world server.
-//!
-//! A simple client that opens a TCP stream, writes "hello world\n", and closes
-//! the connection.
-//!
-//! You can test this out by running:
-//!
-//! ncat -l 6142
-//!
-//! And then in another terminal run:
-//!
-//! cargo run --example hello_world
-
-#![deny(warnings)]
-
-extern crate tokio;
-
-use tokio::io;
-use tokio::net::TcpStream;
-use tokio::prelude::*;
-
-pub fn main() -> Result<(), Box<std::error::Error>> {
- let addr = "127.0.0.1:6142".parse()?;
-
- // Open a TCP stream to the socket address.
- //
- // Note that this is the Tokio TcpStream, which is fully async.
- let client = TcpStream::connect(&addr)
- .and_then(|stream| {
- println!("created stream");
- io::write_all(stream, "hello world\n").then(|result| {
- println!("wrote to stream; success={:?}", result.is_ok());
- Ok(())
- })
- })
- .map_err(|err| {
- // All tasks must have an `Error` type of `()`. This forces error
- // handling and helps avoid silencing failures.
- //
- // In our example, we are only going to log the error to STDOUT.
- println!("connection error = {:?}", err);
- });
-
- // Start the Tokio runtime.
- //
- // The Tokio is a pre-configured "out of the box" runtime for building
- // asynchronous applications. It includes both a reactor and a task
- // scheduler. This means applications are multithreaded by default.
- //
- // This function blocks until the runtime reaches an idle state. Idle is
- // defined as all spawned tasks have completed and all I/O resources (TCP
- // sockets in our case) have been dropped.
- println!("About to create the stream and write to it...");
- tokio::run(client);
- println!("Stream has been created and written to.");
-
- Ok(())
-}