Skip to content

Commit

Permalink
codec: move into tokio-util (tokio-rs#1675)
Browse files Browse the repository at this point in the history
Related to tokio-rs#1318, Tokio APIs that are "less stable" are moved into a new
`tokio-util` crate. This crate will mirror `tokio` and provide
additional APIs that may require a greater rate of breaking changes.

As examples require `tokio-util`, they are moved into a separate
crate (`examples`). This has the added advantage of being able to avoid
example only dependencies in the `tokio` crate.
  • Loading branch information
carllerche authored Oct 22, 2019
1 parent b8cee1a commit cfc1561
Show file tree
Hide file tree
Showing 53 changed files with 318 additions and 479 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

members = [
"tokio",
"tokio-codec",
"tokio-executor",
"tokio-io",
"tokio-macros",
"tokio-net",
"tokio-sync",
"tokio-test",
"tokio-tls",
"tokio-util",

# Internal
"examples",
"build-tests",
]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

```

More examples can be found [here](tokio/examples). Note that the `master` branch
More examples can be found [here](examples). Note that the `master` branch
is currently being updated to use `async` / `await`. The examples are
not fully ported. Examples for stable Tokio can be found
[here](https://github.com/tokio-rs/tokio/tree/v0.1.x/tokio/examples).
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
cross: true
crates:
tokio:
- codec
- fs
- io
- net
Expand Down Expand Up @@ -61,7 +60,6 @@ jobs:
displayName: Test sub crates -
rust: beta
crates:
tokio-codec: []
tokio-executor:
- current-thread
- thread-pool
Expand All @@ -71,6 +69,8 @@ jobs:
- async-traits
tokio-macros: []
tokio-test: []
tokio-util: []
examples: []

# Test compilation failure
- template: ci/azure-test-stable.yml
Expand Down
2 changes: 1 addition & 1 deletion ci/patch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# repository.
[patch.crates-io]
tokio = { path = "tokio" }
tokio-codec = { path = "tokio-codec" }
tokio-executor = { path = "tokio-executor" }
tokio-io = { path = "tokio-io" }
tokio-macros = { path = "tokio-macros" }
tokio-net = { path = "tokio-net" }
tokio-sync = { path = "tokio-sync" }
tokio-tls = { path = "tokio-tls" }
tokio-util = { path = "tokio-util" }
52 changes: 52 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
name = "examples"
version = "0.0.0"
publish = false
edition = "2018"

[dev-dependencies]
tokio = { version = "=0.2.0-alpha.6", path = "../tokio" }
tokio-util = { version = "=0.2.0-alpha.6", path = "../tokio-util" }

bytes = "0.4.12"
futures-preview = "=0.3.0-alpha.19"

[[example]]
name = "chat"
path = "chat.rs"

[[example]]
name = "connect"
path = "connect.rs"

[[example]]
name = "echo-udp"
path = "echo-udp.rs"

[[example]]
name = "echo"
path = "echo.rs"

[[example]]
name = "hello_world"
path = "hello_world.rs"

[[example]]
name = "print_each_packet"
path = "print_each_packet.rs"

[[example]]
name = "proxy"
path = "proxy.rs"

[[example]]
name = "tinydb"
path = "tinydb.rs"

[[example]]
name = "udp-client"
path = "udp-client.rs"

[[example]]
name = "udp-codec"
path = "udp-codec.rs"
File renamed without changes.
22 changes: 12 additions & 10 deletions tokio/examples/chat.rs → examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@
#![warn(rust_2018_idioms)]

use tokio::net::{TcpListener, TcpStream};
use tokio::sync::{mpsc, Mutex};
use tokio_util::codec::{Framed, LinesCodec, LinesCodecError};

use futures::{Poll, SinkExt, Stream, StreamExt};
use std::{
collections::HashMap, env, error::Error, io, net::SocketAddr, pin::Pin, sync::Arc,
task::Context,
};
use tokio::{
self,
codec::{Framed, LinesCodec, LinesCodecError},
net::{TcpListener, TcpStream},
sync::{mpsc, Mutex},
};
use std::collections::HashMap;
use std::env;
use std::error::Error;
use std::io;
use std::net::SocketAddr;
use std::pin::Pin;
use std::sync::Arc;
use std::task::Context;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
Expand Down
21 changes: 10 additions & 11 deletions tokio/examples/connect.rs → examples/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
#![warn(rust_2018_idioms)]

use tokio::io;
use tokio::sync::{mpsc, oneshot};
use tokio_util::codec::{FramedRead, FramedWrite};

use futures::{SinkExt, Stream};
use std::{env, error::Error, net::SocketAddr};
use tokio::{
codec::{FramedRead, FramedWrite},
io,
sync::{mpsc, oneshot},
};
use std::env;
use std::error::Error;
use std::net::SocketAddr;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
Expand Down Expand Up @@ -83,10 +84,8 @@ mod tcp {
use super::codec;
use futures::{future, Sink, SinkExt, Stream, StreamExt};
use std::{error::Error, io, net::SocketAddr};
use tokio::{
codec::{FramedRead, FramedWrite},
net::TcpStream,
};
use tokio::net::TcpStream;
use tokio_util::codec::{FramedRead, FramedWrite};

pub async fn connect(
addr: &SocketAddr,
Expand Down Expand Up @@ -171,7 +170,7 @@ mod udp {
mod codec {
use bytes::{BufMut, BytesMut};
use std::io;
use tokio::codec::{Decoder, Encoder};
use tokio_util::codec::{Decoder, Encoder};

/// A simple `Codec` implementation that just ships bytes around.
///
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@
#![warn(rust_2018_idioms)]

use tokio;
use tokio::codec::{BytesCodec, Decoder};
use tokio::net::TcpListener;
use tokio::prelude::*;
use tokio_util::codec::{BytesCodec, Decoder};

use std::env;

Expand Down
File renamed without changes.
10 changes: 4 additions & 6 deletions tokio/examples/tinydb.rs → examples/tinydb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,15 @@
#![warn(rust_2018_idioms)]

use tokio::net::TcpListener;
use tokio_util::codec::{Framed, LinesCodec};

use futures::{SinkExt, StreamExt};
use std::collections::HashMap;
use std::env;
use std::error::Error;
use std::sync::{Arc, Mutex};

use tokio;
use tokio::codec::{Framed, LinesCodec};
use tokio::net::TcpListener;

use futures::{SinkExt, StreamExt};

/// The in-memory database shared amongst all clients.
///
/// This database will be shared via `Arc`, so to mutate the internal map we're
Expand Down
File renamed without changes.
File renamed without changes.
19 changes: 8 additions & 11 deletions tokio/examples/udp-codec.rs → examples/udp-codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,23 @@
//! new message with a new destination. Overall, we then use this to construct a
//! "ping pong" pair where two sockets are sending messages back and forth.
#![cfg(feature = "rt-full")]
#![warn(rust_2018_idioms)]

use tokio::future::FutureExt as TokioFutureExt;
use tokio::io;
use tokio::net::UdpSocket;
use tokio_util::codec::BytesCodec;
use tokio_util::udp::UdpFramed;

use bytes::Bytes;
use futures::{FutureExt, SinkExt, StreamExt};
use std::env;
use std::error::Error;
use std::net::SocketAddr;
use std::time::Duration;

use bytes::Bytes;

use futures::{FutureExt, SinkExt, StreamExt};
use tokio::codec::BytesCodec;
use tokio::future::FutureExt as TokioFutureExt;
use tokio::io;
use tokio::net::{UdpFramed, UdpSocket};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let _ = env_logger::init();

let addr = env::args().nth(1).unwrap_or("127.0.0.1:0".to_string());

// Bind both our sockets and then figure out what ports we got.
Expand Down
35 changes: 0 additions & 35 deletions tokio-codec/CHANGELOG.md

This file was deleted.

1 change: 0 additions & 1 deletion tokio-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ uds = [
log = ["tracing/log"]

[dependencies]
tokio-codec = { version = "=0.2.0-alpha.6", path = "../tokio-codec" }
tokio-executor = { version = "=0.2.0-alpha.6", features = ["blocking"], path = "../tokio-executor" }
tokio-io = { version = "=0.2.0-alpha.6", path = "../tokio-io" }
tokio-sync = { version = "=0.2.0-alpha.6", path = "../tokio-sync" }
Expand Down
9 changes: 5 additions & 4 deletions tokio-net/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@
//! We can also read input line by line.
//!
//! ```no_run
//! use tokio::io::{BufReader, AsyncBufReadExt};
//! use tokio::process::Command;
//!
//! use futures_util::stream::StreamExt;
//! use std::process::{Stdio};
//! use tokio::codec::{FramedRead, LinesCodec};
//! use tokio_net::process::Command;
//! use std::process::Stdio;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -77,7 +78,7 @@
//! let stdout = child.stdout().take()
//! .expect("child did not have a handle to stdout");
//!
//! let mut reader = FramedRead::new(stdout, LinesCodec::new());
//! let mut reader = BufReader::new(stdout).lines();
//!
//! // Ensure the child process is spawned in the runtime so it can
//! // make progress on its own while we await for any output.
Expand Down
2 changes: 0 additions & 2 deletions tokio-net/src/udp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
//!
//! [`UdpSocket`]: struct.UdpSocket
mod frame;
mod socket;
pub mod split;

pub use self::frame::UdpFramed;
pub use self::socket::UdpSocket;
Loading

0 comments on commit cfc1561

Please sign in to comment.