…定义一个Range
fn test_double_dot() {
use std::ops::Range;
use std::ops::RangeInclusive;
let r1: Range<i32> = 0..10;
let r2: RangeInclusive<i32> = 0..=10;
let nums: Vec<i32> = (0..100).collect();
}
…放在一个对象前面,将对象的成员展开
struct Point {
x: i32,
y: i32,
}
impl Point {
fn new(x: i32, y: i32) -> Self {
Self {
x, y
}
}
}
impl std::fmt::Debug for Point {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({},{})", &self.x, &self.y)
}
}
let p1 = Point::new(2, 6);
println!("{:?}", p1);
let p2 = Point{..p1};
println!("{:?}", p2);
let p3 = Point{x:10, ..p1};
println!("{:?}", p3);