@@ -163,29 +163,6 @@ impl<'a> Row<'a> {
163163 self . stmt . columns ( )
164164 }
165165
166- /// Retrieves the contents of a field of the row.
167- ///
168- /// A field can be accessed by the name or index of its column, though
169- /// access by index is more efficient. Rows are 0-indexed.
170- ///
171- /// Returns an `Error` value if the index does not reference a column or
172- /// the return type is not compatible with the Postgres type.
173- pub fn get_opt < I , T > ( & self , idx : I ) -> Result < T >
174- where I : RowIndex ,
175- T : FromSql
176- {
177- let idx = try!( idx. idx ( self . stmt ) . ok_or ( Error :: InvalidColumn ) ) ;
178- let ty = self . stmt . columns ( ) [ idx] . type_ ( ) ;
179- if !<T as FromSql >:: accepts ( ty) {
180- return Err ( Error :: WrongType ( ty. clone ( ) ) ) ;
181- }
182- let conn = self . stmt . conn ( ) . conn . borrow ( ) ;
183- match self . data [ idx] {
184- Some ( ref data) => FromSql :: from_sql ( ty, & mut & * * data, & SessionInfo :: new ( & * conn) ) ,
185- None => FromSql :: from_sql_null ( ty, & SessionInfo :: new ( & * conn) ) ,
186- }
187- }
188-
189166 /// Retrieves the contents of a field of the row.
190167 ///
191168 /// A field can be accessed by the name or index of its column, though
@@ -209,15 +186,45 @@ impl<'a> Row<'a> {
209186 /// }
210187 /// ```
211188 pub fn get < I , T > ( & self , idx : I ) -> T
212- where I : RowIndex + fmt:: Debug + Clone ,
189+ where I : RowIndex + fmt:: Debug ,
213190 T : FromSql
214191 {
215- match self . get_opt ( idx. clone ( ) ) {
192+ match self . get_inner ( & idx) {
216193 Ok ( ok) => ok,
217194 Err ( err) => panic ! ( "error retrieving column {:?}: {:?}" , idx, err) ,
218195 }
219196 }
220197
198+ /// Retrieves the contents of a field of the row.
199+ ///
200+ /// A field can be accessed by the name or index of its column, though
201+ /// access by index is more efficient. Rows are 0-indexed.
202+ ///
203+ /// Returns an `Error` value if the index does not reference a column or
204+ /// the return type is not compatible with the Postgres type.
205+ pub fn get_opt < I , T > ( & self , idx : I ) -> Result < T >
206+ where I : RowIndex ,
207+ T : FromSql
208+ {
209+ self . get_inner ( & idx)
210+ }
211+
212+ fn get_inner < I , T > ( & self , idx : & I ) -> Result < T >
213+ where I : RowIndex ,
214+ T : FromSql
215+ {
216+ let idx = try!( idx. idx ( self . stmt ) . ok_or ( Error :: InvalidColumn ) ) ;
217+ let ty = self . stmt . columns ( ) [ idx] . type_ ( ) ;
218+ if !<T as FromSql >:: accepts ( ty) {
219+ return Err ( Error :: WrongType ( ty. clone ( ) ) ) ;
220+ }
221+ let conn = self . stmt . conn ( ) . conn . borrow ( ) ;
222+ match self . data [ idx] {
223+ Some ( ref data) => FromSql :: from_sql ( ty, & mut & * * data, & SessionInfo :: new ( & * conn) ) ,
224+ None => FromSql :: from_sql_null ( ty, & SessionInfo :: new ( & * conn) ) ,
225+ }
226+ }
227+
221228 /// Retrieves the specified field as a raw buffer of Postgres data.
222229 ///
223230 /// # Panics
0 commit comments