Skip to main content

TlsPoolComponent

Trait TlsPoolComponent 

pub trait TlsPoolComponent:
    Any
    + Send
    + Sync {
    type Identity: Eq + Hash + Send + Sync + 'static;

    // Required method
    fn pool_component_identity(&self) -> Self::Identity;
}
Available on crate feature rustls only.
Expand description

Explicit pooling identity for a custom TLS configuration component.

Equal identities promise equivalent connection reuse policies. The builder captures an owned identity; it never reads the component again. A value, immutable shared configuration, or TlsComponentIdentity can identify the policy without copying the component itself. Identity equality and hashing must remain stable for the identity’s lifetime.

A mutable component must return a new identity when its policy changes. Use TlsPoolIdBuilder::with_opaque_override if that cannot be guaranteed. Equality of arbitrary callbacks cannot be inferred automatically.

use std::sync::Arc;
use rama_tls::client::{TlsComponentIdentity, TlsPoolComponent, TlsPoolId};

struct VerifyHook(Arc<dyn Fn() -> bool + Send + Sync>);

impl TlsPoolComponent for VerifyHook {
    type Identity = TlsComponentIdentity<dyn Fn() -> bool + Send + Sync>;

    fn pool_component_identity(&self) -> Self::Identity {
        TlsComponentIdentity::shared(&self.0)
    }
}

let hook = Arc::new(VerifyHook(Arc::new(|| true)));
let identity = TlsPoolId::builder().with_component(hook.as_ref()).build();
let clone = Arc::new(VerifyHook(hook.0.clone()));
assert_eq!(identity, TlsPoolId::builder().with_component(clone.as_ref()).build());

Required Associated Types§

type Identity: Eq + Hash + Send + Sync + 'static

An owned, stable snapshot of this component’s reuse policy.

Required Methods§

fn pool_component_identity(&self) -> Self::Identity

Capture the current policy identity independently of this borrow.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§