This works Rust Playground
fn f2(s: Cow<'_, str>) -> Cow<'_, str>
The reason s.deref()
won't work is like what's stated in this post:
-
s.deref()
desugars toDeref::deref<'tmp>(&'tmp Cow<'f, str>) -> &'tmp str
where'f
imposed on thef
function strictly outlives'tmp
- then
f2(s.deref())
isf2(s: &'tmp str) -> Cow<'tmp, str>
and you'll get a shorter lifetime than'f
, thus the error