From 2720246b1a8fee6aa09e79db1ecfb5818f88b21b Mon Sep 17 00:00:00 2001 From: Ivan Ukhov Date: Sat, 21 Nov 2015 19:06:02 +0100 Subject: [PATCH] Let bind take self instead of &self --- src/statement.rs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/statement.rs b/src/statement.rs index d467a02..5e84510 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -25,7 +25,7 @@ pub trait Bindable { /// Bind to a parameter. /// /// The leftmost parameter has the index 1. - fn bind(&self, &mut Statement, usize) -> Result<()>; + fn bind(self, &mut Statement, usize) -> Result<()>; } /// A type suitable for reading from a prepared statement. @@ -107,8 +107,8 @@ impl<'l> Drop for Statement<'l> { } } -impl Bindable for Value { - fn bind(&self, statement: &mut Statement, i: usize) -> Result<()> { +impl<'l> Bindable for &'l Value { + fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { match self { &Value::Binary(ref value) => (value as &[u8]).bind(statement, i), &Value::Float(value) => value.bind(statement, i), @@ -121,7 +121,7 @@ impl Bindable for Value { impl<'l> Bindable for &'l [u8] { #[inline] - fn bind(&self, statement: &mut Statement, i: usize) -> Result<()> { + fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { debug_assert!(i > 0, "the indexing starts from 1"); unsafe { ok!(statement.raw.1, ffi::sqlite3_bind_blob(statement.raw.0, i as c_int, @@ -134,11 +134,11 @@ impl<'l> Bindable for &'l [u8] { impl Bindable for f64 { #[inline] - fn bind(&self, statement: &mut Statement, i: usize) -> Result<()> { + fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { debug_assert!(i > 0, "the indexing starts from 1"); unsafe { ok!(statement.raw.1, ffi::sqlite3_bind_double(statement.raw.0, i as c_int, - *self as c_double)); + self as c_double)); } Ok(()) } @@ -146,11 +146,11 @@ impl Bindable for f64 { impl Bindable for i64 { #[inline] - fn bind(&self, statement: &mut Statement, i: usize) -> Result<()> { + fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { debug_assert!(i > 0, "the indexing starts from 1"); unsafe { ok!(statement.raw.1, ffi::sqlite3_bind_int64(statement.raw.0, i as c_int, - *self as ffi::sqlite3_int64)); + self as ffi::sqlite3_int64)); } Ok(()) } @@ -158,11 +158,11 @@ impl Bindable for i64 { impl<'l> Bindable for &'l str { #[inline] - fn bind(&self, statement: &mut Statement, i: usize) -> Result<()> { + fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { debug_assert!(i > 0, "the indexing starts from 1"); unsafe { ok!(statement.raw.1, ffi::sqlite3_bind_text(statement.raw.0, i as c_int, - str_to_cstr!(*self).into_raw(), -1, + str_to_cstr!(self).into_raw(), -1, Some(drop_cstring))); } Ok(()) @@ -171,7 +171,7 @@ impl<'l> Bindable for &'l str { impl Bindable for () { #[inline] - fn bind(&self, statement: &mut Statement, i: usize) -> Result<()> { + fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { debug_assert!(i > 0, "the indexing starts from 1"); unsafe { ok!(statement.raw.1, ffi::sqlite3_bind_null(statement.raw.0, i as c_int)); @@ -180,12 +180,6 @@ impl Bindable for () { } } -impl<'l, T: Bindable> Bindable for &'l T { - fn bind(&self, statement: &mut Statement, i: usize) -> Result<()> { - (*self).bind(statement, i) - } -} - impl Readable for Value { fn read(statement: &Statement, i: usize) -> Result { Ok(match statement.kind(i) {