Creating Tokio codecs

In Tokio, we have the concept of a codec. A codec is a type that divides a slice of bytes into frames. Each frame will contain certain information parsed from the stream of bytes. In our case, we will read the input of the TCP connection and divide it into chunks each time we find the a letter. A production-ready codec will probably be more complex, but this example will give us a good enough base to implement our own codecs. We will need to implement two traits from the tokio-io crate, so we will need to add it to the [dependencies] section of our Cargo.toml file and import it with extern crate tokio_io;. We will need to do the same with the bytes crate. Now, let's start writing the code:

extern crate bytes;extern crate ...

Get Rust High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.