mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 09:09:19 +08:00
rustfmt
This commit is contained in:
parent
bd81b727f0
commit
20b93bdb96
15
src/cache.rs
15
src/cache.rs
@ -92,9 +92,7 @@ impl<'conn> CachedStatement<'conn> {
|
|||||||
impl StatementCache {
|
impl StatementCache {
|
||||||
/// Create a statement cache.
|
/// Create a statement cache.
|
||||||
pub fn with_capacity(capacity: usize) -> StatementCache {
|
pub fn with_capacity(capacity: usize) -> StatementCache {
|
||||||
StatementCache {
|
StatementCache { cache: RefCell::new(VecDeque::with_capacity(capacity)) }
|
||||||
cache: RefCell::new(VecDeque::with_capacity(capacity)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Search the cache for a prepared-statement object that implements `sql`.
|
/// Search the cache for a prepared-statement object that implements `sql`.
|
||||||
@ -102,10 +100,15 @@ impl StatementCache {
|
|||||||
///
|
///
|
||||||
/// # Failure
|
/// # Failure
|
||||||
///
|
///
|
||||||
/// Will return `Err` if no cached statement can be found and the underlying SQLite prepare call fails.
|
/// Will return `Err` if no cached statement can be found and the underlying SQLite prepare
|
||||||
pub fn get<'conn>(&'conn self, conn: &'conn Connection, sql: &str) -> Result<CachedStatement<'conn>> {
|
/// call fails.
|
||||||
|
pub fn get<'conn>(&'conn self,
|
||||||
|
conn: &'conn Connection,
|
||||||
|
sql: &str)
|
||||||
|
-> Result<CachedStatement<'conn>> {
|
||||||
let mut cache = self.cache.borrow_mut();
|
let mut cache = self.cache.borrow_mut();
|
||||||
let stmt = match cache.iter().rposition(|entry| entry.sql().to_bytes().eq(sql.as_bytes())) {
|
let stmt = match cache.iter()
|
||||||
|
.rposition(|entry| entry.sql().to_bytes().eq(sql.as_bytes())) {
|
||||||
Some(index) => {
|
Some(index) => {
|
||||||
let raw_stmt = cache.swap_remove_front(index).unwrap(); // FIXME Not LRU compliant
|
let raw_stmt = cache.swap_remove_front(index).unwrap(); // FIXME Not LRU compliant
|
||||||
Ok(Statement::new(conn, raw_stmt))
|
Ok(Statement::new(conn, raw_stmt))
|
||||||
|
Loading…
Reference in New Issue
Block a user