mirror of
				https://github.com/isar/rusqlite.git
				synced 2025-10-31 05:48:56 +08:00 
			
		
		
		
	Use associated types instead of generics
This commit is contained in:
		| @@ -89,7 +89,9 @@ impl CSVTab { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl VTab<CSVTabCursor> for CSVTab { | ||||
| impl VTab for CSVTab { | ||||
|     type Cursor = CSVTabCursor; | ||||
|  | ||||
|     unsafe fn connect(db: *mut ffi::sqlite3, _aux: *mut c_void, args: &[&[u8]]) -> Result<CSVTab> { | ||||
|         if args.len() < 4 { | ||||
|             return Err(Error::ModuleError("no CSV file specified".to_owned())); | ||||
| @@ -246,7 +248,9 @@ impl CSVTabCursor { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl VTabCursor<CSVTab> for CSVTabCursor { | ||||
| impl VTabCursor for CSVTabCursor { | ||||
|     type Table = CSVTab; | ||||
|  | ||||
|     fn vtab(&self) -> &CSVTab { | ||||
|         unsafe { & *(self.base.pVtab as *const CSVTab) } | ||||
|     } | ||||
|   | ||||
| @@ -59,7 +59,9 @@ struct IntArrayVTab { | ||||
|     array: *const Rc<RefCell<Vec<i64>>>, | ||||
| } | ||||
|  | ||||
| impl VTab<IntArrayVTabCursor> for IntArrayVTab { | ||||
| impl VTab for IntArrayVTab { | ||||
|     type Cursor = IntArrayVTabCursor; | ||||
|  | ||||
|     unsafe fn connect(db: *mut ffi::sqlite3, | ||||
|                aux: *mut c_void, | ||||
|                _args: &[&[u8]]) | ||||
| @@ -100,7 +102,9 @@ impl IntArrayVTabCursor { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl VTabCursor<IntArrayVTab> for IntArrayVTabCursor { | ||||
| impl VTabCursor for IntArrayVTabCursor { | ||||
|     type Table = IntArrayVTab; | ||||
|  | ||||
|     fn vtab(&self) -> &IntArrayVTab { | ||||
|         unsafe { & *(self.base.pVtab as *const IntArrayVTab) } | ||||
|     } | ||||
|   | ||||
| @@ -41,7 +41,8 @@ use types::{FromSql, FromSqlError, ToSql, ValueRef}; | ||||
| // | ||||
|  | ||||
| /// Virtual table instance trait. | ||||
| pub trait VTab<C: VTabCursor<Self>>: Sized { | ||||
| pub trait VTab: Sized { | ||||
|     type Cursor: VTabCursor; | ||||
|     /// Create a new instance of a virtual table in response to a CREATE VIRTUAL TABLE statement. | ||||
|     /// The `db` parameter is a pointer to the SQLite database connection that is executing | ||||
|     /// the CREATE VIRTUAL TABLE statement. | ||||
| @@ -54,7 +55,7 @@ pub trait VTab<C: VTabCursor<Self>>: Sized { | ||||
|     /// Determine the best way to access the virtual table. | ||||
|     fn best_index(&self, info: &mut IndexInfo) -> Result<()>; | ||||
|     /// Create a new cursor used for accessing a virtual table. | ||||
|     fn open(&self) -> Result<C>; | ||||
|     fn open(&self) -> Result<Self::Cursor>; | ||||
| } | ||||
|  | ||||
| bitflags! { | ||||
| @@ -180,9 +181,10 @@ impl<'a> IndexConstraintUsage<'a> { | ||||
| } | ||||
|  | ||||
| /// Virtual table cursor trait. | ||||
| pub trait VTabCursor<V: VTab<Self>>: Sized { | ||||
| pub trait VTabCursor: Sized { | ||||
|     type Table: VTab; | ||||
|     /// Accessor to the associated virtual table. | ||||
|     fn vtab(&self) -> &V; | ||||
|     fn vtab(&self) -> &Self::Table; | ||||
|     /// Begin a search of a virtual table. | ||||
|     fn filter(&mut self, idx_num: c_int, idx_str: Option<&str>, args: &Values) -> Result<()>; | ||||
|     /// Advance cursor to the next row of a result set initiated by `filter`. | ||||
|   | ||||
| @@ -60,7 +60,9 @@ struct SeriesTab { | ||||
| } | ||||
|  | ||||
|  | ||||
| impl VTab<SeriesTabCursor> for SeriesTab { | ||||
| impl VTab for SeriesTab { | ||||
|     type Cursor = SeriesTabCursor; | ||||
|  | ||||
|     unsafe fn connect(db: *mut ffi::sqlite3, | ||||
|                _aux: *mut c_void, | ||||
|                _args: &[&[u8]]) | ||||
| @@ -171,7 +173,9 @@ impl SeriesTabCursor { | ||||
|         Default::default() | ||||
|     } | ||||
| } | ||||
| impl VTabCursor<SeriesTab> for SeriesTabCursor { | ||||
| impl VTabCursor for SeriesTabCursor { | ||||
|     type Table = SeriesTab; | ||||
|  | ||||
|     fn vtab(&self) -> &SeriesTab { | ||||
|         unsafe { & *(self.base.pVtab as *const SeriesTab) } | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user