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

Char, Bool & Unit

Boolean

  • The boolean type is specified using bool.
  • Booleans are one byte in size.
fn main() {
    // boolean data type inferred 
    let y = false;

    // explicit type annotation
    let x: bool = true; 
}

Character

  • The character type is specified using char.
  • Characters are 4 bytes in size.
  • char is specified with single quotation marks.
fn main() {
    // character data type inferred 
    let c = 'z';
    let heart_eyed_cat = '😻';

    // with explicit type annotation
    let z: char = 'ℤ'; 
}