带有生命周期符号的奇怪编译错误:"expected `:`, found `>`"

Strange compile error with lifetime notation: "expected `:`, found `>`"

我定义了一个结构和方法,如下所示:

struct Lexer<'a> {
    input: String,
    pos: CharIndices<'a>,
    next_pos: Peekable<CharIndices<'a>>,
    ch: char,
}

impl<'a> Lexer<'a> {
    pub fn new(input: String) -> Lexer<'a> {
        let mut lexer = Lexer<'a> {
            input,
            pos: input.char_indices(),
            next_pos: input.char_indices().peekable(),
            ch: char::from(0 as u8),
        };

        lexer
    }
}

编译时出现错误

error: expected `:`, found `>`
  --> src/lexer/mod.rs:15:33
   |
15 |         let mut lexer = Lexer<'a> {
   |                                 ^ expected `:`

然而,按照它的要求将有问题的行更改为 let mut lexer = Lexer<'a:> { 是没有意义的,重新编译确认这确实是不正确的。

error: expected `while`, `for`, `loop` or `{` after a label
  --> src/lexer/mod.rs:15:34
   |
15 |         let mut lexer = Lexer<'a:> {
   |                                  ^ expected `while`, `for`, `loop` or `{` after a label

我不确定为什么编译器会报错,我只能说生命周期符号对我来说很好。

Rust Playground

我刚刚意识到,构造器上不需要一辈子

正确的写法是

let mut lexer = Lexer {

不是

let mut lexer = Lexer<'a> {