mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-26 19:41:37 +08:00
Fix regression with <Cow<'_, _> as ToSql> (#681)
This commit is contained in:
parent
169b3c51fd
commit
76336369ed
@ -90,7 +90,7 @@ pub trait ToSql {
|
|||||||
fn to_sql(&self) -> Result<ToSqlOutput<'_>>;
|
fn to_sql(&self) -> Result<ToSqlOutput<'_>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ToSql + Clone + ?Sized> ToSql for Cow<'_, T> {
|
impl<T: ToSql + ToOwned + ?Sized> ToSql for Cow<'_, T> {
|
||||||
fn to_sql(&self) -> Result<ToSqlOutput<'_>> {
|
fn to_sql(&self) -> Result<ToSqlOutput<'_>> {
|
||||||
self.as_ref().to_sql()
|
self.as_ref().to_sql()
|
||||||
}
|
}
|
||||||
@ -223,17 +223,20 @@ mod test {
|
|||||||
fn test_cow_str() {
|
fn test_cow_str() {
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
let s = "str";
|
let s = "str";
|
||||||
let cow = Cow::Borrowed(s);
|
let cow: Cow<str> = Cow::Borrowed(s);
|
||||||
let r = cow.to_sql();
|
let r = cow.to_sql();
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
let cow = Cow::Owned::<str>(String::from(s));
|
let cow: Cow<str> = Cow::Owned::<str>(String::from(s));
|
||||||
let r = cow.to_sql();
|
let r = cow.to_sql();
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
|
// Ensure this compiles.
|
||||||
|
let _p: &[&dyn ToSql] = crate::params![cow];
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_box_dyn() {
|
fn test_box_dyn() {
|
||||||
let s: Box<dyn ToSql> = Box::new("Hello world!");
|
let s: Box<dyn ToSql> = Box::new("Hello world!");
|
||||||
|
let _s: &[&dyn ToSql] = crate::params![s];
|
||||||
let r = ToSql::to_sql(&s);
|
let r = ToSql::to_sql(&s);
|
||||||
|
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
@ -242,6 +245,7 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_box_deref() {
|
fn test_box_deref() {
|
||||||
let s: Box<str> = "Hello world!".into();
|
let s: Box<str> = "Hello world!".into();
|
||||||
|
let _s: &[&dyn ToSql] = crate::params![s];
|
||||||
let r = s.to_sql();
|
let r = s.to_sql();
|
||||||
|
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
@ -250,6 +254,7 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_box_direct() {
|
fn test_box_direct() {
|
||||||
let s: Box<str> = "Hello world!".into();
|
let s: Box<str> = "Hello world!".into();
|
||||||
|
let _s: &[&dyn ToSql] = crate::params![s];
|
||||||
let r = ToSql::to_sql(&s);
|
let r = ToSql::to_sql(&s);
|
||||||
|
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
@ -261,11 +266,33 @@ mod test {
|
|||||||
|
|
||||||
let source_str: Box<str> = "Hello world!".into();
|
let source_str: Box<str> = "Hello world!".into();
|
||||||
|
|
||||||
let s: Rc<_> = Rc::new(source_str.clone());
|
let s: Rc<Box<str>> = Rc::new(source_str.clone());
|
||||||
|
let _s: &[&dyn ToSql] = crate::params![s];
|
||||||
let r = s.to_sql();
|
let r = s.to_sql();
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
|
|
||||||
let s: Arc<_> = Arc::new(source_str);
|
let s: Arc<Box<str>> = Arc::new(source_str.clone());
|
||||||
|
let _s: &[&dyn ToSql] = crate::params![s];
|
||||||
|
let r = s.to_sql();
|
||||||
|
assert!(r.is_ok());
|
||||||
|
|
||||||
|
let s: Arc<str> = Arc::from(&*source_str);
|
||||||
|
let _s: &[&dyn ToSql] = crate::params![s];
|
||||||
|
let r = s.to_sql();
|
||||||
|
assert!(r.is_ok());
|
||||||
|
|
||||||
|
let s: Arc<dyn ToSql> = Arc::new(source_str.clone());
|
||||||
|
let _s: &[&dyn ToSql] = crate::params![s];
|
||||||
|
let r = s.to_sql();
|
||||||
|
assert!(r.is_ok());
|
||||||
|
|
||||||
|
let s: Rc<str> = Rc::from(&*source_str);
|
||||||
|
let _s: &[&dyn ToSql] = crate::params![s];
|
||||||
|
let r = s.to_sql();
|
||||||
|
assert!(r.is_ok());
|
||||||
|
|
||||||
|
let s: Rc<dyn ToSql> = Rc::new(source_str);
|
||||||
|
let _s: &[&dyn ToSql] = crate::params![s];
|
||||||
let r = s.to_sql();
|
let r = s.to_sql();
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user