Skip to content

Commit

Permalink
Ensure Vec<T> can be used in #[changeset_for]
Browse files Browse the repository at this point in the history
Usually we implement all the various `AsExpression` for refs in the
`expression_impls!` macro. However, that macro doesn't work with generics,
and we forgot to handle `Vec<T>` (I think I figured the slice impl was
enough for some reason).

I tried to write a test for this change, but there are actually several
other bugs that prevent me from testing this properly. See #65 & #66.

Fixes #63.
  • Loading branch information
sgrif committed Dec 20, 2015
1 parent 17809e9 commit ff2ea63
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/
* Add print_sql! and debug_sql! macros to print out and return sql strings from
QueryFragments.

### Fixed

* `#[changeset_for]` can now be used with structs containing a `Vec`. Fixes
[#63](https://github.com/sgrif/diesel/issues/63).

## [0.3.0] 2015-12-04

### Changed
Expand Down
11 changes: 11 additions & 0 deletions diesel/src/types/impls/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ impl<ST, T> AsExpression<Array<ST>> for Vec<T> where
}
}

impl<'a, ST, T> AsExpression<Array<ST>> for &'a Vec<T> where
ST: NativeSqlType,
T: ToSql<ST>,
{
type Expression = Bound<Array<ST>, Self>;

fn as_expression(self) -> Self::Expression {
Bound::new(self)
}
}

impl<'a, ST, T> ToSql<Array<ST>> for &'a [T] where
ST: NativeSqlType,
T: ToSql<ST>,
Expand Down

0 comments on commit ff2ea63

Please sign in to comment.