rust basic

Scalar Type

  • scalar type represents a single value.
  • Rust has four primary scalar types: integers, floating-point numbers, Booleans, and characters.

Character Type

  • char literals with single quotes, as opposed to string literals, which use double quotes
  • Rust’s char type is four bytes in size and represents a Unicode Scalar Value, which means it can represent a lot more than just ASCII. Accented letters; Chinese, Japanese, and Korean characters; emoji; and zero-width spaces are all valid char values in Rust. Unicode Scalar Values range from U+0000 to U+D7FF and U+E000 to U+10FFFF inclusive

Compound Type

Compound types can group multiple values into one type. Rust has two primitive compound types: tuples and arrays.

Tuple

  • Tuples have a fixed length: once declared, they cannot grow or shrink in size.

Array

  • Unlike a tuple, every element of an array must have the same type
  • Arrays are useful when you want your data allocated on the stack rather than the heap.
  • An array isn’t as flexible as the vector type, though. A vector is a similar collection type provided by the standard library that is allowed to grow or shrink in size