Skip to content

Commit c3c3553

Browse files
committed
Fix examples
1 parent 7f198df commit c3c3553

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

postgres/examples/custom_state.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::str::FromStr;
44

55
use bb8::{CustomizeConnection, Pool};
66
use bb8_postgres::PostgresConnectionManager;
7+
use futures_util::future::BoxFuture;
78
use tokio_postgres::config::Config;
89
use tokio_postgres::tls::{MakeTlsConnect, TlsConnect};
910
use tokio_postgres::{Client, Error, Socket, Statement};
@@ -43,14 +44,23 @@ async fn main() {
4344
struct Customizer;
4445

4546
impl CustomizeConnection<CustomPostgresConnection, Error> for Customizer {
46-
async fn on_acquire(&self, conn: &mut CustomPostgresConnection) -> Result<(), Error> {
47-
conn.custom_state
48-
.insert(QueryName::BasicSelect, conn.prepare("SELECT 1").await?);
49-
50-
conn.custom_state
51-
.insert(QueryName::Addition, conn.prepare("SELECT 1 + 1 + 1").await?);
52-
53-
Ok(())
47+
fn on_acquire<'a, 'b, 'r>(
48+
&'a self,
49+
conn: &'b mut CustomPostgresConnection,
50+
) -> BoxFuture<'r, Result<(), Error>>
51+
where
52+
'a: 'r,
53+
'b: 'r,
54+
{
55+
Box::pin(async {
56+
conn.custom_state
57+
.insert(QueryName::BasicSelect, conn.prepare("SELECT 1").await?);
58+
59+
conn.custom_state
60+
.insert(QueryName::Addition, conn.prepare("SELECT 1 + 1 + 1").await?);
61+
62+
Ok(())
63+
})
5464
}
5565
}
5666

0 commit comments

Comments
 (0)