Use AsRef<str> instead of &str

This commit is contained in:
Ivan Ukhov 2015-07-31 16:05:52 -04:00
parent 955172be04
commit 9df0978335
2 changed files with 9 additions and 9 deletions

View File

@ -30,9 +30,9 @@ impl<'l> Connection<'l> {
/// Execute a query without processing the resulting rows if any. /// Execute a query without processing the resulting rows if any.
#[inline] #[inline]
pub fn execute(&self, sql: &str) -> Result<()> { pub fn execute<T: AsRef<str>>(&self, query: T) -> Result<()> {
unsafe { unsafe {
ok!(self.raw, ffi::sqlite3_exec(self.raw, str_to_cstr!(sql).as_ptr(), None, ok!(self.raw, ffi::sqlite3_exec(self.raw, str_to_cstr!(query.as_ref()).as_ptr(), None,
0 as *mut _, 0 as *mut _)); 0 as *mut _, 0 as *mut _));
} }
Ok(()) Ok(())
@ -44,12 +44,12 @@ impl<'l> Connection<'l> {
/// no more rows will be processed. For large queries and non-string data /// no more rows will be processed. For large queries and non-string data
/// types, prepared statement are highly preferable; see `prepare`. /// types, prepared statement are highly preferable; see `prepare`.
#[inline] #[inline]
pub fn process<F>(&self, sql: &str, callback: F) -> Result<()> pub fn process<T: AsRef<str>, F>(&self, query: T, callback: F) -> Result<()>
where F: FnMut(&[(&str, Option<&str>)]) -> bool where F: FnMut(&[(&str, Option<&str>)]) -> bool
{ {
unsafe { unsafe {
let callback = Box::new(callback); let callback = Box::new(callback);
ok!(self.raw, ffi::sqlite3_exec(self.raw, str_to_cstr!(sql).as_ptr(), ok!(self.raw, ffi::sqlite3_exec(self.raw, str_to_cstr!(query.as_ref()).as_ptr(),
Some(process_callback::<F>), Some(process_callback::<F>),
&*callback as *const F as *mut F as *mut _, &*callback as *const F as *mut F as *mut _,
0 as *mut _)); 0 as *mut _));
@ -59,8 +59,8 @@ impl<'l> Connection<'l> {
/// Create a prepared statement. /// Create a prepared statement.
#[inline] #[inline]
pub fn prepare(&'l self, sql: &str) -> Result<Statement<'l>> { pub fn prepare<T: AsRef<str>>(&'l self, query: T) -> Result<Statement<'l>> {
::statement::new(self.raw, sql) ::statement::new(self.raw, query)
} }
/// Set a callback for handling busy events. /// Set a callback for handling busy events.

View File

@ -143,11 +143,11 @@ impl Value for String {
} }
#[inline] #[inline]
pub fn new<'l>(raw1: *mut ffi::sqlite3, sql: &str) -> Result<Statement<'l>> { pub fn new<'l, T: AsRef<str>>(raw1: *mut ffi::sqlite3, query: T) -> Result<Statement<'l>> {
let mut raw0 = 0 as *mut _; let mut raw0 = 0 as *mut _;
unsafe { unsafe {
ok!(raw1, ffi::sqlite3_prepare_v2(raw1, str_to_cstr!(sql).as_ptr(), -1, &mut raw0, ok!(raw1, ffi::sqlite3_prepare_v2(raw1, str_to_cstr!(query.as_ref()).as_ptr(), -1,
0 as *mut _)); &mut raw0, 0 as *mut _));
} }
Ok(Statement { raw: (raw0, raw1), phantom: PhantomData }) Ok(Statement { raw: (raw0, raw1), phantom: PhantomData })
} }