diff --git a/src/vtab/array.rs b/src/vtab/array.rs index 645ab60..1ade815 100644 --- a/src/vtab/array.rs +++ b/src/vtab/array.rs @@ -71,7 +71,7 @@ struct ArrayTab { base: ffi::sqlite3_vtab, } -impl VTab for ArrayTab { +unsafe impl VTab for ArrayTab { type Aux = (); type Cursor = ArrayTabCursor; @@ -149,7 +149,7 @@ impl ArrayTabCursor { } } } -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)?; diff --git a/src/vtab/csvtab.rs b/src/vtab/csvtab.rs index 77570ae..0d8a4c5 100644 --- a/src/vtab/csvtab.rs +++ b/src/vtab/csvtab.rs @@ -95,7 +95,7 @@ impl CSVTab { } } -impl VTab for CSVTab { +unsafe impl VTab for CSVTab { type Aux = (); type Cursor = CSVTabCursor; @@ -296,7 +296,7 @@ impl CSVTabCursor { } } -impl VTabCursor for CSVTabCursor { +unsafe impl VTabCursor for CSVTabCursor { // Only a full table scan is supported. So `filter` simply rewinds to // the beginning. fn filter( diff --git a/src/vtab/mod.rs b/src/vtab/mod.rs index e9b2b10..7421b67 100644 --- a/src/vtab/mod.rs +++ b/src/vtab/mod.rs @@ -189,7 +189,11 @@ impl VTabConnection { /// `feature = "vtab"` Virtual table instance trait. /// -/// Implementations must be like: +/// # Safety +/// +/// The first item in a struct implementing VTab must be +/// `rusqlite::sqlite3_vtab`, and the struct must be `#[repr(C)]`. +/// /// ```rust,ignore /// #[repr(C)] /// struct MyTab { @@ -200,7 +204,7 @@ impl VTabConnection { /// ``` /// /// (See [SQLite doc](https://sqlite.org/c3ref/vtab.html)) -pub trait VTab: Sized { +pub unsafe trait VTab: Sized { type Aux; type Cursor: VTabCursor; @@ -465,7 +469,7 @@ impl OrderBy<'_> { /// ``` /// /// (See [SQLite doc](https://sqlite.org/c3ref/vtab_cursor.html)) -pub trait VTabCursor: Sized { +pub unsafe trait VTabCursor: Sized { /// Begin a search of a virtual table. /// (See [SQLite doc](https://sqlite.org/vtab.html#the_xfilter_method)) fn filter(&mut self, idx_num: c_int, idx_str: Option<&str>, args: &Values<'_>) -> Result<()>; diff --git a/src/vtab/series.rs b/src/vtab/series.rs index 3f4f081..dfc8e69 100644 --- a/src/vtab/series.rs +++ b/src/vtab/series.rs @@ -49,7 +49,7 @@ struct SeriesTab { base: ffi::sqlite3_vtab, } -impl VTab for SeriesTab { +unsafe impl VTab for SeriesTab { type Aux = (); type Cursor = SeriesTabCursor; @@ -181,7 +181,7 @@ impl SeriesTabCursor { SeriesTabCursor::default() } } -impl VTabCursor for SeriesTabCursor { +unsafe impl VTabCursor for SeriesTabCursor { fn filter(&mut self, idx_num: c_int, _idx_str: Option<&str>, args: &Values<'_>) -> Result<()> { let idx_num = QueryPlanFlags::from_bits_truncate(idx_num); let mut i = 0;