Rust, Software Development

Rust – How to check for NULL values

Rust Lang

NULL not supported

Rust does not support NULL unlike some other modern programming languages like Java. Actually, it does not have NULL or null keyword. However, it provides an enum Option used in similar way to Java 8 Optional.

Rust Enforces Variable Initialization

Rust enforces variable initialization both for “global” and “local” variables.

These codes result to the following two separate error messages.

Compile Error 1

Compile Error 2

Using Enum Option

Below is a short code snippet demonstrating how to use the enum Option.


Tested with Rust 1.37.0.


Since NULL or null is not supported, there is no need to check for NULL values in Rust.

You Might Also Like