ConnectionPool

Trait ConnectionPool 

Source
pub trait ConnectionPool:
    Send
    + Sync
    + Debug {
    // Required methods
    fn get<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<ConnectionStream>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn name(&self) -> &str;
    fn status(&self) -> PoolStatus;
    fn host(&self) -> &str;
    fn port(&self) -> u16;
}
Expand description

Connection pool abstraction for async NNTP connections

This trait provides a generic interface for connection pooling, allowing different implementations (real pools, mocks, test doubles) to be used interchangeably throughout the codebase.

§Examples

use nntp_proxy::pool::{ConnectionPool, DeadpoolConnectionProvider};
use async_trait::async_trait;

async fn example(pool: impl ConnectionPool) -> anyhow::Result<()> {
    let conn = pool.get().await?;
    // Use connection...
    Ok(())
}

Required Methods§

Source

fn get<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<ConnectionStream>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get a connection from the pool

Returns a connection that will be automatically returned to the pool when dropped. May create a new connection if none are available.

§Errors

Returns an error if:

  • Connection creation fails
  • Pool is exhausted and cannot create more connections
  • Network errors occur during connection establishment
Source

fn name(&self) -> &str

Get the name/identifier of this connection pool

Used for logging and metrics to distinguish between different backend servers.

Source

fn status(&self) -> PoolStatus

Get current pool statistics

Returns information about pool usage including available connections, maximum size, and total created connections.

Source

fn host(&self) -> &str

Get the backend host this pool connects to

Source

fn port(&self) -> u16

Get the backend port this pool connects to

Implementors§