In this tutorial you will learn about the Rust Custom Types and its application with practical example.
Rust Custom Types
Custom type are data types usually derived using existing data type with another identifier.This user defined data type identifier can later be used to declare variables. In short its purpose is to redefine the name of an existing data type. Rust provides following custom types –
In Rust, we can use arrays when we want hold multiple element of the homogeneous data type in single variable, but what if we want to hold heterogeneous data type element, using structure you can wrap one or more variables that may be in different data types into one.
An enumeration is a set of predefined named values, called as members. Enumerations are useful when we want deal with limited set of values for variable. For example you can think of the colors of a traffic light can only be one of three colors– red, yellow or green.