天天看点

为带有生命周期标注的 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))
    }
}      

原因分析