How do I alter and use this method?

This is what I am trying to figure out how to use:
https://docs.rs/bb8/0.7.0/bb8/struct.Builder.html#method.connection_customizer

Here's some code I was working on but I'm not sure if I'm way off:

#[derive(Debug)]
struct ConnectionCustomizer {}
impl bb8_postgres::bb8::CustomizeConnection<PooledConnection<'_,PostgresConnectionManager<MakeTlsConnector>>, anyhow::Error>
for ConnectionCustomizer
{
    fn on_acquire(&self, connection: &mut PooledConnection<PostgresConnectionManager<MakeTlsConnector>>) -> Result<(), anyhow::Error> {
        println!("test");
        Ok(())
    }
}

and I would use it like:

.connection_customizer(Box::new(ConnectionCustomizer {}))

You'll need to use the async_trait crate to have it match the definition of the CustomizeConnection trait.

I originally tried that but I am just lost to the syntax here. Could you show me an example?

I greatly appreciate your quick response.

Something like this:

#[async_trait]
impl
    bb8_postgres::bb8::CustomizeConnection<
        PooledConnection<'_, PostgresConnectionManager<MakeTlsConnector>>,
        anyhow::Error,
    > for ConnectionCustomizer
{
    async fn on_acquire(
        &self,
        connection: &mut PooledConnection<PostgresConnectionManager<MakeTlsConnector>>,
    ) -> Result<(), anyhow::Error> {
        println!("test");
        Ok(())
    }
}

I just keep getting a lifetime specifier error related to PooledConnection<'_, PostgresConnectionManager>

I couldn't figure out if that is supposed to that that bb8 type or if it wanted the actual tokio_postgres Connection type.

Try this

#[async_trait]
impl<'a>
    bb8_postgres::bb8::CustomizeConnection<
        PooledConnection<'a, PostgresConnectionManager<MakeTlsConnector>>,
        anyhow::Error,
    > for ConnectionCustomizer
{
    async fn on_acquire(
        &self,
        connection: &mut PooledConnection<'a, PostgresConnectionManager<MakeTlsConnector>>,
    ) -> Result<(), anyhow::Error> {
        println!("test");
        Ok(())
    }
}
error[E0478]: lifetime bound not satisfied
  --> src/lib/once.rs:63:1
   |
63 | / bb8_postgres::bb8::CustomizeConnection<
64 | |     PooledConnection<'a, PostgresConnectionManager<MakeTlsConnector>>,
65 | |     anyhow::Error,
66 | | > for ConnectionCustomizer
   | |_^
   |
note: lifetime parameter instantiated with the lifetime `'a` as defined on the impl at 62:6
  --> src/lib/once.rs:62:6
   |
62 | impl<'a>
   |      ^^
   = note: but lifetime parameter must outlive the static lifetime

Sounds like you're using the wrong type. I would probably open an issue on the github repo and ask there.

Thanks, will do

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.