feat: implement Encode, Decode, Type for Arc<str> and Arc<[u8]> (and Rc equivalents) (#3675)

* implement Encode, Decode, Type for Arc<str> and Arc<[u8]> (and Rc equivalents)

* sqlx-sqlite: Remove clone in Encode impl

* sqlx-sqlite: Remove unnecessary impls
This commit is contained in:
Joey de Waal
2025-07-05 02:58:33 +02:00
committed by GitHub
parent 0f891a3c56
commit 60f67dbc39
10 changed files with 93 additions and 63 deletions

View File

@@ -1,4 +1,6 @@
use std::borrow::Cow;
use std::rc::Rc;
use std::sync::Arc;
use crate::decode::Decode;
use crate::encode::{Encode, IsNull};
@@ -102,3 +104,21 @@ impl<'q> Encode<'q, Sqlite> for Cow<'q, [u8]> {
Ok(IsNull::No)
}
}
impl<'q> Encode<'q, Sqlite> for Arc<[u8]> {
fn encode_by_ref(
&self,
args: &mut Vec<SqliteArgumentValue<'q>>,
) -> Result<IsNull, BoxDynError> {
<Vec<u8> as Encode<'_, Sqlite>>::encode(self.to_vec(), args)
}
}
impl<'q> Encode<'q, Sqlite> for Rc<[u8]> {
fn encode_by_ref(
&self,
args: &mut Vec<SqliteArgumentValue<'q>>,
) -> Result<IsNull, BoxDynError> {
<Vec<u8> as Encode<'_, Sqlite>>::encode(self.to_vec(), args)
}
}

View File

@@ -1,4 +1,6 @@
use std::borrow::Cow;
use std::rc::Rc;
use std::sync::Arc;
use crate::decode::Decode;
use crate::encode::{Encode, IsNull};
@@ -94,3 +96,21 @@ impl<'q> Encode<'q, Sqlite> for Cow<'q, str> {
Ok(IsNull::No)
}
}
impl<'q> Encode<'q, Sqlite> for Arc<str> {
fn encode_by_ref(
&self,
args: &mut Vec<SqliteArgumentValue<'q>>,
) -> Result<IsNull, BoxDynError> {
<String as Encode<'_, Sqlite>>::encode(self.to_string(), args)
}
}
impl<'q> Encode<'q, Sqlite> for Rc<str> {
fn encode_by_ref(
&self,
args: &mut Vec<SqliteArgumentValue<'q>>,
) -> Result<IsNull, BoxDynError> {
<String as Encode<'_, Sqlite>>::encode(self.to_string(), args)
}
}