Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加元组结构体解构语法 #1016

Open
slgxmh opened this issue Sep 6, 2022 · 0 comments
Open

增加元组结构体解构语法 #1016

slgxmh opened this issue Sep 6, 2022 · 0 comments

Comments

@slgxmh
Copy link

slgxmh commented Sep 6, 2022

问题描述

在本书元组结构体部分,仅说明了声明元组结构体的语法,但是在对应的练习中练习中,第三题:

// 填空并修复错误
struct Color(i32, i32, i32);
struct Point(i32, i32, i32);
fn main() {
    let v = Point(__, __, __);
    check_color(v);
}   

fn check_color(p: Color) {
    let (x, _, _) = p; // 这个地方需要使用解构语法,需要改正为let Point(x,y,z)=p
    assert_eq!(x, 0);
    assert_eq!(p.1, 127);
    assert_eq!(__, 255);
 }

元组结构体解构需要再次声明类型,建议在书中增加相关说明,我作为新手不看答案真不知道。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant