Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Integer

Type name: int

Rust type: i64

An integer is a whole number, which can be positive, negative, or zero. Under the hood, integers are represented as 64-bit signed integers.

<int>42</int>
<int>-7</int>
<int>0</int>

Conversion to other types

When converting an int to other types, it behaves exactly as you would expect:

  • float: A float with the same value and a fractional part of .0.
  • bool: true if the value is non-zero, false if it is zero.
  • string: The string representation of the integer, e.g., the string 42.