除了范围之外,还有更多的方法可以在Rust中使用..(dotdot)吗?

时间:2018-02-22 02:31:09

标签: rust

我发现..可以通过这种方式在结构中使用:

struct Test {
    e1: i32,
    e2: i32,
}

fn main() {
    let test = Test { e1: 1, e2: 2 };
    let Test { e1: x, .. } = test;
    let Test { e2: y, .. } = test;
    let test2 = Test { ..test };
    let test3 = Test { e1: 2, e2: 3, ..test };
}

有更多方法可以使用..吗?在某处有他们的概述吗?

1 个答案:

答案 0 :(得分:3)

不,没有其他用法,您可以看到in the reference

  • (..expr):right-exclusive range literal。
  • (variant(x, ..), struct_type { x, .. }):struct literal update syntax。
  • a { display: inline-flex; /* takes only the contents width; you can also use "flex" (100% width) */ flex-direction: column; /* stacks flex-items (children) vertically */ align-items: center; /* centers them horizontally */ }:“和其他”模式绑定。