From 7867d195fc51b4dc2776d1307a8216b679c0def0 Mon Sep 17 00:00:00 2001 From: Ivan Petkov Date: Sat, 19 Mar 2022 10:37:27 -0700 Subject: [PATCH] sqlx-core: impl Type for Cow on Mssql, MySql, and Sqlite --- sqlx-core/src/mssql/types/str.rs | 10 ++++++++++ sqlx-core/src/mysql/types/str.rs | 10 ++++++++++ sqlx-core/src/sqlite/types/str.rs | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/sqlx-core/src/mssql/types/str.rs b/sqlx-core/src/mssql/types/str.rs index 048dd84cd3..2f4ae9f99b 100644 --- a/sqlx-core/src/mssql/types/str.rs +++ b/sqlx-core/src/mssql/types/str.rs @@ -83,6 +83,16 @@ impl Decode<'_, Mssql> for String { } } +impl Type for Cow<'_, str> { + fn type_info() -> MssqlTypeInfo { + <&str as Type>::type_info() + } + + fn compatible(ty: &MssqlTypeInfo) -> bool { + <&str as Type>::compatible(ty) + } +} + impl Encode<'_, Mssql> for Cow<'_, str> { fn produces(&self) -> Option { match self { diff --git a/sqlx-core/src/mysql/types/str.rs b/sqlx-core/src/mysql/types/str.rs index 076858901b..231500f08e 100644 --- a/sqlx-core/src/mysql/types/str.rs +++ b/sqlx-core/src/mysql/types/str.rs @@ -82,6 +82,16 @@ impl Decode<'_, MySql> for String { } } +impl Type for Cow<'_, str> { + fn type_info() -> MySqlTypeInfo { + <&str as Type>::type_info() + } + + fn compatible(ty: &MySqlTypeInfo) -> bool { + <&str as Type>::compatible(ty) + } +} + impl Encode<'_, MySql> for Cow<'_, str> { fn encode_by_ref(&self, buf: &mut Vec) -> IsNull { match self { diff --git a/sqlx-core/src/sqlite/types/str.rs b/sqlx-core/src/sqlite/types/str.rs index 086597ef10..5db0b039d0 100644 --- a/sqlx-core/src/sqlite/types/str.rs +++ b/sqlx-core/src/sqlite/types/str.rs @@ -53,6 +53,16 @@ impl<'r> Decode<'r, Sqlite> for String { } } +impl Type for Cow<'_, str> { + fn type_info() -> SqliteTypeInfo { + <&str as Type>::type_info() + } + + fn compatible(ty: &SqliteTypeInfo) -> bool { + <&str as Type>::compatible(ty) + } +} + impl<'q> Encode<'q, Sqlite> for Cow<'q, str> { fn encode(self, args: &mut Vec>) -> IsNull { args.push(SqliteArgumentValue::Text(self));