在Rust中,<‘_’>是什么意思?

3

以下是来自Debug示例的代码:

use std::fmt;

struct Point {
    x: i32,
    y: i32,
}

impl fmt::Debug for Point {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("Point")
         .field("x", &self.x)
         .field("y", &self.y)
         .finish()
    }
}

let origin = Point { x: 0, y: 0 };

assert_eq!(format!("The origin is: {origin:?}"), "The origin is: Point { x: 0, y: 0 }");

f: &mut fmt::Formatter<'_> 中,<'_> 是什么意思?它表示一个匿名生命周期。

https://doc.rust-lang.org/rust-by-example/scope/lifetime.html - bill.gates
1个回答

6

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接