Understanding Tuples in Rust Programming

preview_player
Показать описание
Here's a quick peek at how tuples in Rust look. Rust is a strong, typed language, like Java and other similar ones that require you to clearly define the variable type and name. The process in Rust is simple, just name your variable, let's say a tuple, and assign it.

What sets a tuple apart from an array is the flexibility it offers by allowing for a mixture of data types. It can hold various arrays of numbers, for example, 8-bit unsigned, 16-bit unsigned, 32-bit unsigned and even 64-bit unsigned. There's also an I for signed, which seems odd.

It's not clear why it isn't an S. Besides these, tuples can also contain floating point numbers, characters, strings, boolean values and more. If you tried cramming all these into an array, the compiler would reject it.

What's even cooler is that tuples can house other tuples within them. So, you could have a tuple with a single value and a non-tuple value.
Рекомендации по теме