Rust定义并实例化结构体

Rust 中使用 struct 关键字定义并实例化结构体。

示例程序:

struct User {
    username: String,
    email: String,
    sign_in_count: u64,
    actice: bool,
}

fn main() {
    let user1 = User {
        username: String::from("yuyoubei"),
        email: String::from("yuyoubei@qq.com"),
        actice: true,
        sign_in_count: 123,
    };

    println!("{}, {}, {}, {}", user1.username, user1.email, user1.actice, user1.sign_in_count); // 输出 yuyoubei, yuyoubei@qq.com, true, 123
}
上一篇:python实现微信hmac_sha256和md5加密签名


下一篇:1763.最长的美好子字符串