mirror of
				https://github.com/isar/rusqlite.git
				synced 2025-11-01 06:18:54 +08:00 
			
		
		
		
	Allow optionally passing an Error parameter to rusqlite::Result (#678)
				
					
				
			This commit is contained in:
		
							
								
								
									
										12
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/lib.rs
									
									
									
									
									
								
							| @@ -204,7 +204,7 @@ macro_rules! named_params { | ||||
| } | ||||
|  | ||||
| /// A typedef of the result returned by many methods. | ||||
| pub type Result<T> = result::Result<T, Error>; | ||||
| pub type Result<T, E = Error> = result::Result<T, E>; | ||||
|  | ||||
| /// See the [method documentation](#tymethod.optional). | ||||
| pub trait OptionalExtension<T> { | ||||
| @@ -602,11 +602,11 @@ impl Connection { | ||||
|     /// | ||||
|     /// Will return `Err` if `sql` cannot be converted to a C-compatible string | ||||
|     /// or if the underlying SQLite call fails. | ||||
|     pub fn query_row_and_then<T, E, P, F>(&self, sql: &str, params: P, f: F) -> result::Result<T, E> | ||||
|     pub fn query_row_and_then<T, E, P, F>(&self, sql: &str, params: P, f: F) -> Result<T, E> | ||||
|     where | ||||
|         P: IntoIterator, | ||||
|         P::Item: ToSql, | ||||
|         F: FnOnce(&Row<'_>) -> result::Result<T, E>, | ||||
|         F: FnOnce(&Row<'_>) -> Result<T, E>, | ||||
|         E: convert::From<Error>, | ||||
|     { | ||||
|         let mut stmt = self.prepare(sql)?; | ||||
| @@ -647,7 +647,7 @@ impl Connection { | ||||
|     /// # Failure | ||||
|     /// | ||||
|     /// Will return `Err` if the underlying SQLite call fails. | ||||
|     pub fn close(self) -> std::result::Result<(), (Connection, Error)> { | ||||
|     pub fn close(self) -> Result<(), (Connection, Error)> { | ||||
|         self.flush_prepared_statement_cache(); | ||||
|         let r = self.db.borrow_mut().close(); | ||||
|         r.map_err(move |err| (self, err)) | ||||
| @@ -1492,7 +1492,7 @@ mod test { | ||||
|         } | ||||
|  | ||||
|         impl fmt::Display for CustomError { | ||||
|             fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { | ||||
|             fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { | ||||
|                 match *self { | ||||
|                     CustomError::SomeError => write!(f, "my custom error"), | ||||
|                     CustomError::Sqlite(ref se) => write!(f, "my custom error: {}", se), | ||||
| @@ -1519,7 +1519,7 @@ mod test { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         type CustomResult<T> = ::std::result::Result<T, CustomError>; | ||||
|         type CustomResult<T> = Result<T, CustomError>; | ||||
|  | ||||
|         #[test] | ||||
|         fn test_query_and_then() { | ||||
|   | ||||
							
								
								
									
										10
									
								
								src/row.rs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/row.rs
									
									
									
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
| use fallible_iterator::FallibleIterator; | ||||
| use fallible_streaming_iterator::FallibleStreamingIterator; | ||||
| use std::{convert, result}; | ||||
| use std::convert; | ||||
|  | ||||
| use super::{Error, Result, Statement}; | ||||
| use crate::types::{FromSql, FromSqlError, ValueRef}; | ||||
| @@ -56,7 +56,7 @@ impl<'stmt> Rows<'stmt> { | ||||
|     /// `FallibleStreamingIterator`). | ||||
|     pub fn and_then<F, T, E>(self, f: F) -> AndThenRows<'stmt, F> | ||||
|     where | ||||
|         F: FnMut(&Row<'_>) -> result::Result<T, E>, | ||||
|         F: FnMut(&Row<'_>) -> Result<T, E>, | ||||
|     { | ||||
|         AndThenRows { rows: self, map: f } | ||||
|     } | ||||
| @@ -143,7 +143,7 @@ pub struct AndThenRows<'stmt, F> { | ||||
|  | ||||
| impl<'stmt, T, E, F> AndThenRows<'stmt, F> | ||||
| where | ||||
|     F: FnMut(&Row<'_>) -> result::Result<T, E>, | ||||
|     F: FnMut(&Row<'_>) -> Result<T, E>, | ||||
| { | ||||
|     pub(crate) fn new(rows: Rows<'stmt>, f: F) -> AndThenRows<'stmt, F> { | ||||
|         AndThenRows { rows, map: f } | ||||
| @@ -153,9 +153,9 @@ where | ||||
| impl<T, E, F> Iterator for AndThenRows<'_, F> | ||||
| where | ||||
|     E: convert::From<Error>, | ||||
|     F: FnMut(&Row<'_>) -> result::Result<T, E>, | ||||
|     F: FnMut(&Row<'_>) -> Result<T, E>, | ||||
| { | ||||
|     type Item = result::Result<T, E>; | ||||
|     type Item = Result<T, E>; | ||||
|  | ||||
|     fn next(&mut self) -> Option<Self::Item> { | ||||
|         let map = &mut self.map; | ||||
|   | ||||
| @@ -3,7 +3,7 @@ use std::os::raw::{c_int, c_void}; | ||||
| #[cfg(feature = "array")] | ||||
| use std::rc::Rc; | ||||
| use std::slice::from_raw_parts; | ||||
| use std::{convert, fmt, mem, ptr, result, str}; | ||||
| use std::{convert, fmt, mem, ptr, str}; | ||||
|  | ||||
| use super::ffi; | ||||
| use super::{len_as_c_int, str_for_sqlite, str_to_cstring}; | ||||
| @@ -284,7 +284,7 @@ impl Statement<'_> { | ||||
|         P: IntoIterator, | ||||
|         P::Item: ToSql, | ||||
|         E: convert::From<Error>, | ||||
|         F: FnMut(&Row<'_>) -> result::Result<T, E>, | ||||
|         F: FnMut(&Row<'_>) -> Result<T, E>, | ||||
|     { | ||||
|         let rows = self.query(params)?; | ||||
|         Ok(AndThenRows::new(rows, f)) | ||||
| @@ -335,7 +335,7 @@ impl Statement<'_> { | ||||
|     ) -> Result<AndThenRows<'_, F>> | ||||
|     where | ||||
|         E: convert::From<Error>, | ||||
|         F: FnMut(&Row<'_>) -> result::Result<T, E>, | ||||
|         F: FnMut(&Row<'_>) -> Result<T, E>, | ||||
|     { | ||||
|         let rows = self.query_named(params)?; | ||||
|         Ok(AndThenRows::new(rows, f)) | ||||
|   | ||||
| @@ -24,7 +24,6 @@ | ||||
| use std::fs::File; | ||||
| use std::os::raw::c_int; | ||||
| use std::path::Path; | ||||
| use std::result; | ||||
| use std::str; | ||||
|  | ||||
| use crate::ffi; | ||||
| @@ -70,7 +69,7 @@ struct CSVTab { | ||||
| } | ||||
|  | ||||
| impl CSVTab { | ||||
|     fn reader(&self) -> result::Result<csv::Reader<File>, csv::Error> { | ||||
|     fn reader(&self) -> Result<csv::Reader<File>, csv::Error> { | ||||
|         csv::ReaderBuilder::new() | ||||
|             .has_headers(self.has_headers) | ||||
|             .delimiter(self.delimiter) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user