Search⌘ K

Effects Versus Results

Explore how Rust expressions produce values by distinguishing between effects and results. Understand the special unit type () used when expressions have no meaningful value, and see practical examples including macro calls and assertions.

We'll cover the following...

What is the value of this expression?

Rust 1.40.0
println!("Hello, world!")

Most people would think that it’s the string “Hello, world!” That’s not actually the case. We need to talk about the difference between an effect and a result.

An effect is something that is caused when you evaluate an expression. In our example above, the macro call println! causes the output to be printed to the screen. You could have a program that talks to Amazon with a function call order_pokeballs(12) that causes 12 Pokeballs to be sent to your house. That would be the effect of evaluating that expression. ...