0

I don't understand line 3 in the code below. It is a macro expansion of the FromRow trait in sqlx. I through that 'a denoted a lifetime? It seems in this expansion it is being treated as a type and constrained? What does this line mean?

       impl<'a, R: ::sqlx::Row> ::sqlx::FromRow<'a, R> for LitRel
         where
         &'a ::std::primitive::str: ::sqlx::ColumnIndex<R>, //<--- ?
         String: ::sqlx::decode::Decode<'a, R::Database>,
         String: ::sqlx::types::Type<R::Database>,
tjb
  • 11,480
  • 9
  • 70
  • 91

1 Answers1

0

It looks to me &'a ::std::primitive::str together is a type, string slice, and 'a is its lifetime.

Joe_Jingyu
  • 1,024
  • 6
  • 9
  • do you know why the lifetime is needed here in the where clause? (wouldn't it be enough to just constrain the type directly [i.e. remove &'a altogether?]) – tjb Dec 07 '21 at 07:05
  • Sorry I have no knowledge of that. There is another thing strange to me. Per the sqlx::FromRow [documentation](https://docs.rs/sqlx/0.5.1/sqlx/trait.FromRow.html), the macro should always generate a bound `usize: ColumnIndex`. I don't know why for your case it is `&'a ::std::primitive::str`, instead of `usize`, is bound to `ColumnIndex`. If it is a question for you too, maybe you can raise another question with more information of the struct `LitRel`. – Joe_Jingyu Dec 07 '21 at 07:43
  • Don't know, I'm using the sqlite database, maybe that is the reason? – tjb Dec 07 '21 at 09:16