Struct PassedRef

Source
#[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§

Source§

impl<T: 'static> PassedRef<T>

Source

pub fn new(value: T) -> PassedRef<T>

Create a new PassedRef containing the value.

Trait Implementations§

Source§

impl<T: 'static> Debug for PassedRef<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T: 'static> ToParam for PassedRef<T>

Sets the parameter to NULL with this value as an associated pointer.

Source§

fn bind_param(self, stmt: &mut Statement, pos: i32) -> Result<()>

Bind this value to the prepared Statement at the provided position. Read more
Source§

impl<T: 'static> ToContextResult for PassedRef<T>

Sets the context result to NULL with this value as an associated pointer.

Auto Trait Implementations§

§

impl<T> Freeze for PassedRef<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for PassedRef<T>
where T: RefUnwindSafe,

§

impl<T> Send for PassedRef<T>
where T: Send,

§

impl<T> Sync for PassedRef<T>
where T: Sync,

§

impl<T> Unpin for PassedRef<T>
where T: Unpin,

§

impl<T> UnwindSafe for PassedRef<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.