pub trait FindFunctionVTab<'vtab>: VTab<'vtab> {
// Required method
fn functions(&'vtab self) -> &'vtab VTabFunctionList<'vtab, Self>;
}Expand description
A virtual table that overloads some functions.
A virtual table implementation may choose to overload certain functions when the first argument to the function refers to a column in the virtual table. To do this, add a VTabFunctionList to the virtual table struct and return a reference to it from the functions method. When a function uses a column from this virtual table as its first argument, the returned list will be checked to see if the virtual table would like to overload the function.
Overloading additionally allows the virtual table to indicate that the virtual table is able to exploit the function to speed up a query result. For this to work, the function must take exactly two arguments and appear as a boolean in the WHERE clause of a query. The ConstraintOp supplied with the function will then be provided as an IndexInfoConstraint to VTab::best_index. This feature additionally requires SQLite 3.25.0.
For more details, see the SQLite documentation.
§Example
Here is a brief summary of how to use this trait:
use sqlite3_ext::{function::*, vtab::*, *};
#[sqlite3_ext_vtab(StandardModule)]
struct MyVTab<'vtab> {
/// Used to store the overloaded functions
functions: VTabFunctionList<'vtab, Self>
}
impl MyVTab<'_> {
/// Register the overloaded functions. Should be called from connect/create.
fn init_functions(&mut self) {
self.functions.add_method(1, "my_func", None, |vtab, ctx, args| {
println!("my_func was called");
ctx.set_result(&*args[0])
});
}
}
/// Return the owned functions list.
impl<'vtab> FindFunctionVTab<'vtab> for MyVTab<'vtab> {
fn functions(&self) -> &VTabFunctionList<'vtab, Self> {
&self.functions
}
}Required Methods§
Sourcefn functions(&'vtab self) -> &'vtab VTabFunctionList<'vtab, Self>
fn functions(&'vtab self) -> &'vtab VTabFunctionList<'vtab, Self>
Retrieve a reference to the VTabFunctionList associated with this virtual table.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.