fix FromRow derive to take &Row

This commit is contained in:
Ryan Leckey 2020-03-24 03:08:58 -07:00
parent e71b969e78
commit dcea3f0586
3 changed files with 4 additions and 4 deletions

View file

@ -31,7 +31,7 @@ where
impl<'c, R, I> ColumnIndex<'c, R> for &'_ I
where
R: Row<'c>,
I: ColumnIndex<'c, R>,
I: ColumnIndex<'c, R> + ?Sized,
{
#[inline]
fn index(&self, row: &R) -> crate::Result<<R as Row<'c>>::Database, usize> {
@ -44,7 +44,7 @@ mod private_column_index {
pub trait Sealed {}
impl Sealed for usize {}
impl Sealed for str {}
impl<T> Sealed for &'_ T where T: Sealed {}
impl<T> Sealed for &'_ T where T: Sealed + ?Sized {}
}
/// Represents a single row from the database.

View file

@ -86,7 +86,7 @@ fn expand_derive_from_row_struct(
Ok(quote!(
impl #impl_generics sqlx::row::FromRow<#lifetime, R> for #ident #ty_generics #where_clause {
fn from_row(row: R) -> sqlx::Result<R::Database, Self> {
fn from_row(row: &R) -> sqlx::Result<R::Database, Self> {
#(#reads)*
Ok(#ident {

View file

@ -125,7 +125,7 @@ async fn test_from_row() -> anyhow::Result<()> {
.bind(1_i32)
.fetch(&mut conn);
let account = RefAccount::from_row(cursor.next().await?.unwrap())?;
let account = RefAccount::from_row(&cursor.next().await?.unwrap())?;
assert_eq!(account.id, 1);
assert_eq!(account.name, "Herp Derpinson");