sunface / rust-by-practice

Learning Rust By Practice, narrowing the gap between beginner and skilled-dev through challenging examples, exercises and projects.

Home Page:https://practice.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

结构体第三题

greyhawk opened this issue · comments

struct Color(i32, i32, i32);
struct Point(i32, i32, i32);
fn main() {
    let v = Color(0, 127, 255);
    check_color(v);
}   

fn check_color(p: Color) {
    let Color(x,_,_) = p;
    assert_eq!(x, 0);
    assert_eq!(p.1, 127);
    assert_eq!(p.2, 255);
 }

额...有点小困惑,这里的问题是?

代码没问题呢,感觉函数名是 check color,传一个 color struct 更合理 😏

好的,我看看。。