mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +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 {
|
||||
/// Create a statement cache.
|
||||
pub fn with_capacity(capacity: usize) -> StatementCache {
|
||||
StatementCache {
|
||||
cache: RefCell::new(VecDeque::with_capacity(capacity)),
|
||||
}
|
||||
StatementCache { cache: RefCell::new(VecDeque::with_capacity(capacity)) }
|
||||
}
|
||||
|
||||
/// Search the cache for a prepared-statement object that implements `sql`.
|
||||
@ -102,10 +100,15 @@ impl StatementCache {
|
||||
///
|
||||
/// # Failure
|
||||
///
|
||||
/// Will return `Err` if no cached statement can be found and the underlying SQLite prepare call fails.
|
||||
pub fn get<'conn>(&'conn self, conn: &'conn Connection, sql: &str) -> Result<CachedStatement<'conn>> {
|
||||
/// Will return `Err` if no cached statement can be found and the underlying SQLite prepare
|
||||
/// call fails.
|
||||
pub fn get<'conn>(&'conn self,
|
||||
conn: &'conn Connection,
|
||||
sql: &str)
|
||||
-> Result<CachedStatement<'conn>> {
|
||||
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) => {
|
||||
let raw_stmt = cache.swap_remove_front(index).unwrap(); // FIXME Not LRU compliant
|
||||
Ok(Statement::new(conn, raw_stmt))
|
||||
|
Loading…
Reference in New Issue
Block a user