diff --git a/src/lib.rs b/src/lib.rs index 24605a90..9cec27ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -332,8 +332,8 @@ pub struct PostgresCancelData { /// # let _ = /// postgres::cancel_query(url, &NoSsl, cancel_data); /// ``` -pub fn cancel_query(params: T, ssl: &SslMode, data: PostgresCancelData) - -> Result<(), PostgresConnectError> { +pub fn cancel_query(params: T, ssl: &SslMode, data: PostgresCancelData) + -> Result<(), PostgresConnectError> where T: IntoConnectParams { let params = try!(params.into_connect_params()); let mut socket = match io::initialize_stream(¶ms, ssl) { @@ -373,8 +373,9 @@ impl Drop for InnerPostgresConnection { } impl InnerPostgresConnection { - fn connect(params: T, ssl: &SslMode) - -> Result { + fn connect(params: T, ssl: &SslMode) + -> Result + where T: IntoConnectParams { let params = try!(params.into_connect_params()); let stream = try!(io::initialize_stream(¶ms, ssl)); @@ -716,8 +717,8 @@ impl PostgresConnection { /// }; /// let maybe_conn = PostgresConnection::connect(params, &NoSsl); /// ``` - pub fn connect(params: T, ssl: &SslMode) - -> Result { + pub fn connect(params: T, ssl: &SslMode) -> Result + where T: IntoConnectParams { InnerPostgresConnection::connect(params, ssl).map(|conn| { PostgresConnection { conn: RefCell::new(conn) } }) @@ -998,7 +999,7 @@ impl<'conn> PostgresTransaction<'conn> { stmt: &'stmt PostgresStatement, params: &[&ToSql], row_limit: i32) - -> PostgresResult> { + -> PostgresResult> { if self.conn as *const _ != stmt.conn as *const _ { return Err(PgWrongConnection); } @@ -1385,13 +1386,12 @@ impl<'stmt> PostgresRow<'stmt> { /// /// Returns an `Error` value if the index does not reference a column or /// the return type is not compatible with the Postgres type. - pub fn get_opt(&self, idx: I) -> PostgresResult { + pub fn get_opt(&self, idx: I) -> PostgresResult where I: RowIndex, T: FromSql { let idx = match idx.idx(self.stmt) { Some(idx) => idx, None => return Err(PgInvalidColumn) }; - FromSql::from_sql(&self.stmt.result_desc[idx].ty, - &self.data[idx]) + FromSql::from_sql(&self.stmt.result_desc[idx].ty, &self.data[idx]) } /// Retrieves the contents of a field of the row. @@ -1415,7 +1415,7 @@ impl<'stmt> PostgresRow<'stmt> { /// let foo: i32 = row.get(0u); /// let bar: String = row.get("bar"); /// ``` - pub fn get(&self, idx: I) -> T { + pub fn get(&self, idx: I) -> T where I: RowIndex + fmt::Show + Clone, T: FromSql { match self.get_opt(idx.clone()) { Ok(ok) => ok, Err(err) => fail!("error retrieving column {}: {}", idx, err) @@ -1451,8 +1451,7 @@ impl RowIndex for uint { impl<'a> RowIndex for &'a str { #[inline] fn idx(&self, stmt: &PostgresStatement) -> Option { - stmt.result_descriptions().iter() - .position(|d| d.name.as_slice() == *self) + stmt.result_descriptions().iter().position(|d| d.name.as_slice() == *self) } }