< 返回版块

Mike Tang 发表于 2018-03-05 15:43

Tags:rust,pattern

看这里,

https://doc.rust-lang.org/book/second-edition/appendix-02-operators.html

.. (variant(x, ..), struct_type { x, .. }): “and the rest” pattern binding.

这句话什么意思,怎么用?

评论区

写评论
作者 Mike Tang 2018-03-05 15:53

原来是用在match里面。

@CrLF0710 pub struct Point { pub x: i32, pub y: i32, }

fn main() { let pt = Point {x: 4, y: 5};

println!("{}", match pt {
Point {x, .. } => x
});

}

codeworm96 2018-03-05 15:49
CrLF0710 2018-03-05 15:49
pub struct Point {
    pub x: i32,
    pub y: i32,
}

fn main() {
    let pt = Point {x: 4, y: 5};
    
    println!("{}", match pt {
    Point {x, .. } => x
    });
}
1 共 3 条评论, 1 页