Skip to content

Day 07 - 结构体与枚举 ​

结构体 ​

rust
struct User {
    username: String,
    email: String,
    active: bool,
}

let user = User {
    username: String::from("alice"),
    email: String::from("alice@example.com"),
    active: true,
};

枚举 ​

rust
enum Message {
    Quit,
    Move { x: i32, y: i32 },
    Write(String),
    ChangeColor(i32, i32, i32),
}

Match ​

rust
enum Color {
    Red,
    Green,
    Blue,
}

fn print_color(c: Color) {
    match c {
        Color::Red => println!("red"),
        Color::Green => println!("green"),
        Color::Blue => println!("blue"),
    }
}

📅 学习进度 ​

Day主题状态
01-06基础✅
07结构体与枚举✅
08Option与Result⬜

本文为Rust 30天学习计划第7天内容 ​

📚 导航 ​

| ← Day 06 - 上一章 | Day 08 - 下一章 →

最后更新: