mirror of
				https://github.com/isar/rusqlite.git
				synced 2025-10-31 05:48:56 +08:00 
			
		
		
		
	VTabCursor lifetime should be bound to VTab lifetime
```c
struct sqlite3_vtab_cursor {
  sqlite3_vtab *pVtab;      /* Virtual table of this cursor */
```
It seems that we need to introduce a lifetime on `VTab` trait
to express such constraint:
https://users.rust-lang.org/t/associated-type-with-lifetime-bound/7256
But there may be another/new way to do it.
			
			
This commit is contained in:
		| @@ -27,6 +27,7 @@ | ||||
| //! ``` | ||||
|  | ||||
| use std::default::Default; | ||||
| use std::marker::PhantomData; | ||||
| use std::os::raw::{c_char, c_int, c_void}; | ||||
| use std::rc::Rc; | ||||
|  | ||||
| @@ -72,9 +73,9 @@ struct ArrayTab { | ||||
|     base: ffi::sqlite3_vtab, | ||||
| } | ||||
|  | ||||
| unsafe impl VTab for ArrayTab { | ||||
| unsafe impl<'vtab> VTab<'vtab> for ArrayTab { | ||||
|     type Aux = (); | ||||
|     type Cursor = ArrayTabCursor; | ||||
|     type Cursor = ArrayTabCursor<'vtab>; | ||||
|  | ||||
|     fn connect( | ||||
|         _: &mut VTabConnection, | ||||
| @@ -118,28 +119,30 @@ unsafe impl VTab for ArrayTab { | ||||
|         Ok(()) | ||||
|     } | ||||
|  | ||||
|     fn open(&self) -> Result<ArrayTabCursor> { | ||||
|     fn open(&'vtab self) -> Result<ArrayTabCursor<'vtab>> { | ||||
|         Ok(ArrayTabCursor::new()) | ||||
|     } | ||||
| } | ||||
|  | ||||
| /// A cursor for the Array virtual table | ||||
| #[repr(C)] | ||||
| struct ArrayTabCursor { | ||||
| struct ArrayTabCursor<'vtab> { | ||||
|     /// Base class. Must be first | ||||
|     base: ffi::sqlite3_vtab_cursor, | ||||
|     /// The rowid | ||||
|     row_id: i64, | ||||
|     /// Pointer to the array of values ("pointer") | ||||
|     ptr: Option<Array>, | ||||
|     phantom: PhantomData<&'vtab ArrayTab>, | ||||
| } | ||||
|  | ||||
| impl ArrayTabCursor { | ||||
|     fn new() -> ArrayTabCursor { | ||||
| impl ArrayTabCursor<'_> { | ||||
|     fn new<'vtab>() -> ArrayTabCursor<'vtab> { | ||||
|         ArrayTabCursor { | ||||
|             base: ffi::sqlite3_vtab_cursor::default(), | ||||
|             row_id: 0, | ||||
|             ptr: None, | ||||
|             phantom: PhantomData, | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -150,7 +153,7 @@ impl ArrayTabCursor { | ||||
|         } | ||||
|     } | ||||
| } | ||||
| unsafe impl VTabCursor for ArrayTabCursor { | ||||
| unsafe impl VTabCursor for ArrayTabCursor<'_> { | ||||
|     fn filter(&mut self, idx_num: c_int, _idx_str: Option<&str>, args: &Values<'_>) -> Result<()> { | ||||
|         if idx_num > 0 { | ||||
|             self.ptr = args.get_array(0)?; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user