Support newtype refs by mirroring diesel's AsExpression derive #30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed that the following type of
Insertable
struct was not supported:This yields the following compiler error when I run tests:
The interesting part here is the last line, where
&'insert &'a MyIdString
must beAsExpression<diesel::sql_types::Text>
. If you inspect Diesel'sAsExpression
macro [here](https://github.com/diesel-rs/diesel/blob/7bd8b8f208046188e24d5dab2cd12aebba10846d/diesel_derives/src/as_expression.rs#L63-L71 , we see that this is implemented when you#[derive(AsExpression)]
.This PR adds in this double-reference implementation. Additionally, to make this work I mirrored another part of Diesel's derive, using
Self/self
in place of explicit types. I'm not familiar enough with Diesels' internals to know whatBound
does exactly, but matching Diesel's macro seems to maintain functionality.I also noticed that Diesel's
AsExpression
macro had some special implementations forNullable
that this crate doesn't replicate. To double check that this worked properly, I added some tests that usedNullable
types. We seem to get those implicitly here without any extra implementation, I think from this built-in impl paired with this crate's generic approach.