#![forbid(unsafe_code, future_incompatible)]
#![deny(
missing_debug_implementations,
nonstandard_style,
missing_docs,
unreachable_pub,
missing_copy_implementations,
unused_qualifications
)]
use std::sync::Arc;
#[derive(Debug)]
pub struct PooledSessionStore<M: r2d2::ManageConnection> {
pool: Arc<r2d2::Pool<M>>,
table_name: String,
}
impl<M: r2d2::ManageConnection> Clone for PooledSessionStore<M> {
fn clone(&self) -> Self {
Self {
pool: self.pool.clone(),
table_name: self.table_name.clone(),
}
}
}
pub trait TableOperations<M: r2d2::ManageConnection> {
fn add_table(&self) -> async_session::Result<()>;
fn clean_up(&self) -> async_session::Result<()>;
fn connection(&self) -> async_session::Result<r2d2::PooledConnection<M>>;
fn count(&self) -> async_session::Result<usize>;
}
impl<M: r2d2::ManageConnection> PooledSessionStore<M> {
pub fn from_pool(pool: r2d2::Pool<M>, table_name: String) -> async_session::Result<Self>
where
Self: TableOperations<M>,
{
let session = Self {
pool: Arc::new(pool),
table_name,
};
session.add_table().and(Ok(session))
}
}
#[cfg(feature = "with-rusqlite")]
pub mod sqlite;
#[cfg(test)]
mod test;