Erro: found concrete lifetime


Hello guys, I am trying but, I am not being able to understand what does this error below mean:

src/lib/core/ 52:6 error: method index has an incompatible type for trait: expected bound lifetime parameter 'a, found concrete lifetime [E0053]
src/lib/core/ fn index(&'a self, _index: &'a str) -> &'a Row {
src/lib/core/ self
src/lib/core/ }

Can someone help me with this?


Looks like the definition is displayed differently in the documentation for std and core, where the trait comes from. This shows that the signature for index is fn index<'a>(&'a self, index: Idx) -> &'a Self::Output. Note the index<'a> part.



Thank you for your response, but for example I have this struct:

pub struct Row<'a> {
    stm         : String,
    field       : &'a str

How could I implement Index correctly? If I try to do this:

impl Index<String> for Row {
    type Output = Row;

    fn index<'b>(&'b self, _index: String) -> &'b Row {

I get this error:

error: wrong number of lifetime parameters: expected 1, found 0


You have to define a separate lifetime parameter for the struct itself:

impl<'a> Index<String> for Row<'a> {
    type Output = Row<'a>;

    fn index<'b>(&'b self, _index: String) -> &'b Row<'a> {

'b is the lifetime of the borrow of self in index and 'a is the lifetime of the content in Row<'a>.


Many thanks Ogeon, it worked! now I understand better.