我想返回向量的一部分,但编译器抱怨&;[Letter]需要显式的生存期.
struct Board {
board: Vec<Letter>,
width: usize,
height: usize,
}
impl std::ops::Index<usize> for Board {
type Output = &[Letter];
fn index(&self, index: usize) -> &Self::Output {
return &&self.board[index * self.width..(index + 1) * self.width];
}
}
我曾try 添加一个明确的生存期,但没有奏效.