I have a struct with one member:
pub struct Term<'a>(pub &'a str);
I also have a Vec<Term>
and I want to convert the Vec
to Iterator
and then lowercase the &str
, like:
pub fn add_vec(document: Vec<Term<'a>>) {
let m_term = document.into_iter().map(
|dx| Term(dx.0.to_lowercase().as_str())
).collect::<Vec<_>>();
}
but I'm seeing this error:
error: borrowed value does not live long enough
--> src/tfidf.rs:47:23
|
47 | |dx| Term(dx.0.to_lowercase().as_str())
| ^^^^^^^^^^^^^^^^^^^ - temporary value only lives until here
| |
| temporary value created here
|
note: borrowed value must be valid for the lifetime 'a as defined on the block at 44:55...
I think I understand what the problem is, but I don't know how can I convert the String
result of to_lowercase()
to a &str
with lifetime of 'a
.