Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to_sql for bytes Cow as well #1051

Merged
merged 2 commits into from
Jul 20, 2023
Merged

Add to_sql for bytes Cow as well #1051

merged 2 commits into from
Jul 20, 2023

Conversation

andrewbaxter
Copy link
Contributor

No description provided.

@andrewbaxter andrewbaxter marked this pull request as draft July 20, 2023 13:54
@andrewbaxter andrewbaxter changed the title Draft: Add to_sql for bytes Cow as well Add to_sql for bytes Cow as well Jul 20, 2023
@@ -1035,6 +1035,18 @@ impl<T: ToSql> ToSql for Box<[T]> {
to_sql_checked!();
}

impl<'a> ToSql for Cow<'a, [u8]> {
fn to_sql(&self, ty: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
<&str as ToSql>::to_sql(&self.as_ref(), ty, w)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str -> [u8], and you shouldn't need the .as_ref().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, sorry, was just testing it locally. I'll fix that now!

Copy link
Contributor Author

@andrewbaxter andrewbaxter Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without as_ref I get

error[E0308]: mismatched types
    --> postgres-types/src/lib.rs:1040:34
     |
1040 |         <&[u8] as ToSql>::to_sql(&self, ty, w)
     |         ------------------------ ^^^^^ expected `&&[u8]`, found `&&Cow<'_, [u8]>`
     |         |
     |         arguments to this function are incorrect
     |
     = note: expected reference `&&[u8]`
                found reference `&&Cow<'a, [u8]>`
note: method defined here
    --> postgres-types/src/lib.rs:851:8
     |
851  |     fn to_sql(&self, ty: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>>
     |        ^^^^^^

Copy link
Contributor Author

@andrewbaxter andrewbaxter Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The str thing was fixed, I think this is ready to go. And thanks for the fast review!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, you'd need to do the same &&**self dance you can see above. This works as well though.

@andrewbaxter andrewbaxter marked this pull request as ready for review July 20, 2023 14:30
@sfackler sfackler merged commit d16a9cd into sfackler:master Jul 20, 2023
@sfackler
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants