Creating a data structure is one of the ways to add a new data type to Rust. A data structure is a group of variables that have been attached to each other, resulting in a single new data type that means all of these, together.
A new structure is defined using the struct keyword:
pub struct Constrained {
pub min: i32,
pub max: i32,
current: i32,
}
Notice the commas after each contained variable is defined. It can be tempting to use semicolons there, but that would cause a compiler error. The final comma is optional, but recommended, because it means that the lines can be rearranged without having to pay attention to where a comma might be missing, among other reasons.
Here, we've defined a structure called Constrained, which is made up of three different 32-bit unsigned integer variables. The structure itself is public, meaning that it can be used...