My Rust side note

Almost everything is an expression

Ly Channa
Mar 19, 2024

You may wonder what parts of Rust are not expressions and, thus, do not return values.

Statements are not expressions. These appear in Rust in three places:

 1. Expressions delimited by the semicolon (;)

2. Binding a name to a value with the assignment operator (=)

 3. Type declarations, which include functions (fn) and data types created with the struct and enum keywords.

Formally, the first form is referred to as an expression statement.

The last two are both called declaration statements. In Rust, no value is represented as () (the“unit” type).

--

--

Ly Channa
Ly Channa

Written by Ly Channa

Highly skilled: REST API, OAuth2, OpenIDConnect, SSO, TDD, RubyOnRails, CI/CD, Infrastruct as Code, AWS.

No responses yet