pub struct SqlVec<T: ToString + FromStr>(/* private fields */);Expand description
A generic container for vectors whose contents implement ToString & FromStr.
SqlVec implements ToSql & FromSql storing values as \u{F1} delimited text, allowing for SQL operations.
§Example
use sqlvec::SqlVec;
use rusqlite::{Error, Connection, params};
let conn = Connection::open_in_memory().unwrap();
// Create a table with a column that uses our custom type.
conn.execute(
"CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, data TEXT);",
[],
).unwrap();
// Insert a SqlVec into the table.
let values = SqlVec::new(vec!["one".to_string(), "two".to_string()]);
conn.execute(
"INSERT INTO test (data) VALUES (?1)",
params![values],
).unwrap();
// Retrieve the SqlVec from the table.
let mut stmt = conn.prepare("SELECT data FROM test WHERE id = ?1").unwrap();
let mut rows = stmt.query(params![1]).unwrap();
let row = rows.next().unwrap().unwrap();
let db_values: SqlVec<String> = row.get(0).unwrap();
// Assert that the retrieved SqlVec matches the original.
assert_eq!(values, db_values);Implementations§
source§impl<T: ToString + FromStr> SqlVec<T>
impl<T: ToString + FromStr> SqlVec<T>
sourcepub fn new<I: IntoIterator<Item = T>>(items: I) -> Self
pub fn new<I: IntoIterator<Item = T>>(items: I) -> Self
Creates a new SqlVec from an iterable collection of items.
§Example
use sqlvec::SqlVec;
let vec = SqlVec::new([1, 2, 3]);
sourcepub fn into_inner(self) -> Vec<T>
pub fn into_inner(self) -> Vec<T>
Consumes the SqlVec, returning its internal vector.
This method allows you to take ownership of the underlying vector contained within the SqlVec. After calling into_inner, the SqlVec cannot be used anymore unless recreated.
§Example
use sqlvec::SqlVec;
let sql_vec = SqlVec::new(vec![1, 2]);
let vec = sql_vec.into_inner();
assert_eq!(vec, vec![1, 2]);
Trait Implementations§
source§impl<T: ToString + FromStr> FromIterator<T> for SqlVec<T>
impl<T: ToString + FromStr> FromIterator<T> for SqlVec<T>
source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
source§impl<T: ToString + FromStr> FromSql for SqlVec<T>
impl<T: ToString + FromStr> FromSql for SqlVec<T>
source§fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self>
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self>
Converts SQLite value into Rust value.
source§impl<T: PartialEq + ToString + FromStr> PartialEq for SqlVec<T>
impl<T: PartialEq + ToString + FromStr> PartialEq for SqlVec<T>
source§impl<T: ToString + FromStr> ToSql for SqlVec<T>
impl<T: ToString + FromStr> ToSql for SqlVec<T>
source§fn to_sql(&self) -> Result<ToSqlOutput<'_>>
fn to_sql(&self) -> Result<ToSqlOutput<'_>>
Converts Rust value to SQLite value
impl<T: Eq + ToString + FromStr> Eq for SqlVec<T>
impl<T: ToString + FromStr> StructuralPartialEq for SqlVec<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for SqlVec<T>where
T: RefUnwindSafe,
impl<T> Send for SqlVec<T>where
T: Send,
impl<T> Sync for SqlVec<T>where
T: Sync,
impl<T> Unpin for SqlVec<T>where
T: Unpin,
impl<T> UnwindSafe for SqlVec<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more