pub struct SqliteValue(/* private fields */);Expand description
An owned handle to a sqlite3_value.
§Note: Decoding is Stateful
The sqlite3_value interface reserves the right to be stateful:
Other interfaces might change the datatype for an sqlite3_value object. For example, if the datatype is initially SQLITE_INTEGER and sqlite3_value_text(V) is called to extract a text value for that integer, then subsequent calls to sqlite3_value_type(V) might return SQLITE_TEXT. Whether or not a persistent internal datatype conversion occurs is undefined and may change from one release of SQLite to the next.
Thus, this type is !Sync and SqliteValueRef is !Send and !Sync to prevent data races.
Additionally, this statefulness means that the return values of sqlite3_value_bytes() and
sqlite3_value_blob() could be invalidated by later calls to other sqlite3_value* methods.
To prevent undefined behavior from accessing dangling pointers, this type (and any
SqliteValueRef instances created from it) remembers when it was used to decode a
borrowed &[u8] or &str and returns an error if it is used to decode any other type.
To bypass this error, you must prove that no outstanding borrows exist.
This may be done in one of a few ways:
- If you hold mutable access, call
Self::reset_borrow()which resets the borrowed state. - If you have an immutable reference, call
Self::clone()to get a new instance with no outstanding borrows. - If you hold a
SqliteValueRef, callSqliteValueRef::to_owned()to get a newSqliteValuewith no outstanding borrows.
This is only necessary if using the same SqliteValue or SqliteValueRef to decode
multiple different types. The vast majority of use-cases employing once-through decoding
should not have to worry about this.
Implementations§
Source§impl SqliteValue
impl SqliteValue
Sourcepub fn reset_borrow(&mut self)
pub fn reset_borrow(&mut self)
Prove that there are no outstanding borrows of this instance.
Call this after decoding a borrowed &[u8] or &str
to reset the internal borrowed state and allow decoding of other types.
Sourcepub fn try_clone(&self) -> Result<SqliteValue, SqliteError>
pub fn try_clone(&self) -> Result<SqliteValue, SqliteError>
Call sqlite3_value_dup() to create a new instance of this type.
Returns an error if the call returns a null pointer, indicating that SQLite was unable to allocate the additional memory required.
Non-panicking version of Self::clone().
Trait Implementations§
Source§impl Clone for SqliteValue
impl Clone for SqliteValue
Source§fn clone(&self) -> SqliteValue
fn clone(&self) -> SqliteValue
Call sqlite3_value_dup() to create a new instance of this type.
§Panics
If sqlite3_value_dup() returns a null pointer, indicating an out-of-memory condition.
See Self::try_clone() for a non-panicking version.
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Value for SqliteValue
impl Value for SqliteValue
type Database = Sqlite
Source§fn as_ref(&self) -> SqliteValueRef<'_>
fn as_ref(&self) -> SqliteValueRef<'_>
Source§fn type_info(&self) -> Cow<'_, SqliteTypeInfo>
fn type_info(&self) -> Cow<'_, SqliteTypeInfo>
Source§fn decode_unchecked<'r, T>(&'r self) -> T
fn decode_unchecked<'r, T>(&'r self) -> T
Auto Trait Implementations§
impl !Freeze for SqliteValue
impl !RefUnwindSafe for SqliteValue
impl !Sync for SqliteValue
impl Send for SqliteValue
impl Unpin for SqliteValue
impl UnsafeUnpin for SqliteValue
impl UnwindSafe for SqliteValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more