-
-
Notifications
You must be signed in to change notification settings - Fork 451
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
Conversation
postgres-types/src/lib.rs
Outdated
@@ -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) |
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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>>
| ^^^^^^
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
Thanks! |
No description provided.