天天看點

為帶有生命周期标注的 struct 實作 trait 的問題

問題描述

use std::str::FromStr;

pub struct Wrapper<'a>(&'a str);

impl FromStr for Wrapper<'_> {
    type Err = ();
    
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(Wrapper(s))
    }
}      

原因分析