“error: expected item, found ‘let’”

Your fundamental issue is that let can only be used in a function. So, wrapping the code in main(), and also fixing the style:

fn if_statements() {
    let x = 5;

    let y = if x == 5 { 10 } else { 15 };

    if y == 15 {
        println!("y = {}", y);
    }
}

#[allow(dead_code)]
fn add(a: i32, b: i32) -> i32 { a + b }

#[allow(dead_code)]
fn crash(exception: &str) -> ! {
    panic!("{}", exception);
 }

struct Point {
     x: i32,
     y: i32,
}

fn structs() {
    let origin = Point { x: 0, y: 0 };

    println!("The origin is at ({}, {})", origin.x, origin.y);
}

enum Character {
    Digit(i32),
    Other,
}

fn main() {
    let y = (1, "hello");
    let x: (i32, &str) = (1, "hello");

    let ten  = Character::Digit(10);
    let four = Character::Digit(4);
 }

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)