Skip to content

Commit

Permalink
add some inline attributes for roa-diesel
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexilee committed Mar 4, 2020
1 parent b994521 commit bc3501a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions roa-diesel/src/async_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub trait SqlQuery<Conn: 'static + Connection> {
Limit<Q>: LoadQuery<Conn, U>;
}

#[inline]
fn map_diesel_error(err: DieselError) -> Error {
WrapError::from(err).into()
}
Expand All @@ -93,6 +94,7 @@ where
S: State + AsRef<Pool<Conn>>,
Conn: 'static + Connection,
{
#[inline]
async fn execute<E>(&self, exec: E) -> Result<usize>
where
E: 'static + Send + ExecuteDsl<Conn>,
Expand Down Expand Up @@ -122,6 +124,7 @@ where
/// [`execute`]: fn.execute.html
/// [`sql_query`]: ../fn.sql_query.html
///
#[inline]
async fn load_data<U, Q>(&self, query: Q) -> Result<Vec<U>>
where
U: 'static + Send,
Expand All @@ -144,6 +147,7 @@ where
/// When this method is called on an insert, update, or delete statement,
/// it will implicitly add a `RETURNING *` to the query,
/// unless a returning clause was already specified.
#[inline]
async fn get_result<U, Q>(&self, query: Q) -> Result<Option<U>>
where
U: 'static + Send,
Expand All @@ -163,6 +167,7 @@ where
/// sense for insert, update, and delete statements.
///
/// [`load`]: #method.load
#[inline]
async fn get_results<U, Q>(&self, query: Q) -> Result<Vec<U>>
where
U: 'static + Send,
Expand All @@ -179,6 +184,7 @@ where
/// returned. If the query truly is optional, you can call `.optional()` on
/// the result of this to get a `Result<Option<U>>`.
///
#[inline]
async fn first<U, Q>(&self, query: Q) -> Result<Option<U>>
where
U: 'static + Send,
Expand Down
4 changes: 4 additions & 0 deletions roa-diesel/src/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum WrapError {
}

impl Display for WrapError {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
use WrapError::*;
match self {
Expand All @@ -25,18 +26,21 @@ impl Display for WrapError {
}

impl From<DieselError> for WrapError {
#[inline]
fn from(err: DieselError) -> Self {
WrapError::Diesel(err)
}
}

impl From<PoolError> for WrapError {
#[inline]
fn from(err: PoolError) -> Self {
WrapError::Pool(err)
}
}

impl From<WrapError> for Error {
#[inline]
fn from(err: WrapError) -> Self {
Error::new(StatusCode::INTERNAL_SERVER_ERROR, err, false)
}
Expand Down
3 changes: 3 additions & 0 deletions roa-diesel/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ where
S: State + AsRef<Pool<Conn>>,
Conn: Connection + 'static,
{
#[inline]
async fn get_conn(&self) -> Result<WrapConnection<Conn>, Error> {
let pool = self.as_ref().clone();
self.exec
Expand All @@ -100,6 +101,7 @@ where
.map_err(|err| WrapError::from(err).into())
}

#[inline]
async fn get_timeout(
&self,
timeout: Duration,
Expand All @@ -111,6 +113,7 @@ where
.map_err(|err| WrapError::from(err).into())
}

#[inline]
async fn pool_state(&self) -> r2d2::State {
let pool = self.as_ref().clone();
self.exec.spawn_blocking(move || pool.state()).await
Expand Down

0 comments on commit bc3501a

Please sign in to comment.