在 impl 中省略生命周期

Minimum Rust version: nightly

在编写 impl 时,你可以提及生命周期而不将它们绑定在参数列表中。

在 Rust 2015 中:

impl<'a> Iterator for MyIter<'a> { ... }
impl<'a, 'b> SomeTrait<'a> for SomeType<'a, 'b> { ... }

在 Rust 2018 中:

impl Iterator for MyIter<'iter> { ... }
impl SomeTrait<'tcx> for SomeType<'tcx, 'gcx> { ... }