Skip to Content
Rust Programming By Example
book

Rust Programming By Example

by Guillaume Gomez, Antoni Boucher
January 2018
Beginner to intermediate
454 pages
10h 8m
English
Packt Publishing
Content preview from Rust Programming By Example

Print output to stdout

Let's see what happens when we add a call to println!() in our test (for debug purposes, for instance):

#[test]
fn test_pwd() {
    println!("Running FTP server");

    // …
}

It will not be printed to the terminal. In order to see it, we need to pass another parameter to the test runner. Let's run cargo test this way to see the output to stdout:

cargo run -- --nocapture

This time, we see the following output:

… Running target/debug/deps/server-1b5cda64792f5f82 running 1 test Running FTP server Waiting clients on port 1234... New client: [address : 127.0.0.1:43304] Waiting another client... Received command: Pwd Received command: User("ferris") Received command: Cwd("src") Received command: Pwd Received command: CdUp Received ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Rust Programming Cookbook

Rust Programming Cookbook

Claus Matzinger
Rust Web Programming

Rust Web Programming

Maxwell Flitton

Publisher Resources

ISBN: 9781788390637Supplemental Content