liveBook · Manning

Read trait

As explained in Rust Servers, Services, and Apps

The Rust standard-library Read trait defines byte-reading behavior for types that provide input from a source.

The Rust standard-library Read trait defines shared byte-reading behavior. File, Stdin, TcpStream, and user-defined types can implement it, exposing the same read() method across input sources. section 2.2.2

Reading and echoing TCP data

A TCP server imports Read, allocates a mutable byte buffer, and calls stream.read(&mut buffer). A client writes "Hello", reads five bytes into its buffer, and prints the UTF-8 response.

How Rust Servers, Services, and Apps covers it

How deep it goes
Defines shared behavior, the required read() method, and common implementers, then demonstrates one buffered socket read.
Examples
Demonstrates Read with a TCP server buffer and a client receiving the echoed string "Hello".
What you can do after
Apply it via std::io::Read to read bytes from a TCP stream into a mutable buffer.
How it connects
Connects Read with Rust traits, Write, byte-oriented sources, TcpStream, File, and Stdin.

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.