#[repr(C)]pub struct PassedRef<T: 'static> { /* private fields */ }
Expand description
Pass arbitrary values through SQLite.
Values of this type can be passed into SQL queries and returned by SQL functions, and later retrieved using ValueRef::get_ref. SQLite takes ownership of the stored value, and does not provide any mechanism for getting a PassedRef from a query result, so this feature is primarily useful for passing values into SQL, or between application-defined functions.
This mechanism relies on std::any::Any to ensure type safety, which requires that values
are 'static
. If you want to transfer a reference through a PassedRef, use a shared
pointer like std::rc::Rc.
This feature requires SQLite 3.20.0. On earlier versions of SQLite, returning a PassedRef object from an application-defined function has no effect. If supporting older versions of SQLite is required, UnsafePtr can be used instead.
§Examples
This example shows produce_ref
returning a PassedRef which is later consumed by
consume_ref
.
use sqlite3_ext::{PassedRef, function::Context, Result, ValueRef};
fn produce_ref(ctx: &Context, args: &mut [&mut ValueRef]) -> PassedRef<String> {
let val = "owned string".to_owned();
PassedRef::new(val)
}
fn consume_ref(ctx: &Context, args: &mut [&mut ValueRef]) -> Result<()> {
let val = args[0].get_ref::<String>().unwrap();
assert_eq!(val, "owned string");
Ok(())
}
Implementations§
Trait Implementations§
Source§impl<T: 'static> ToParam for PassedRef<T>
Sets the parameter to NULL with this value as an associated pointer.
impl<T: 'static> ToParam for PassedRef<T>
Sets the parameter to NULL with this value as an associated pointer.
impl<T: 'static> ToContextResult for PassedRef<T>
Sets the context result to NULL with this value as an associated pointer.