pub trait ServerConfigStreamBuilder {
type ConfigStream: Stream<Item = Result<Arc<ServerConfig>, ServerConfigStreamError>> + Send + Sync + Unpin + 'static;
// Required method
fn build(
&mut self,
) -> impl Future<Output = Result<Self::ConfigStream, ServerConfigStreamError>> + Send;
}Expand description
A factory for producing a stream of rustls::ServerConfig.
Implement this trait to define how your application sources TLS configs (e.g., file watchers, secret managers, pull-from-API).
The returned stream should yield complete ServerConfig values. Each
item replaces the provider’s current config atomically (via ArcSwap).
§Contract
build()should return a stream that eventually yields at least oneServerConfigduring initial startup. If it doesn’t, startup will fail withServerConfigStreamError::EmptyStream.- On stream failure, the provider will call
build()again with backoff. - Items from the stream should be independent
Arc<ServerConfig>values.
§Examples
use std::sync::Arc;
use rustls::ServerConfig;
use tokio_stream::{Stream, wrappers::ReceiverStream};
struct MyConfigProvider;
impl ServerConfigStreamBuilder for MyConfigProvider {
type ConfigStream = ReceiverStream<Result<Arc<ServerConfig>, ServerConfigStreamError>>;
async fn build(
&mut self,
) -> Result<Self::ConfigStream, ServerConfigStreamError> {
// Construct a stream that yields ServerConfig updates.
// See the SPIFFE implementation in [`rustls-spiffe`] for a full example.
unimplemented!()
}
}Required Associated Types§
Sourcetype ConfigStream: Stream<Item = Result<Arc<ServerConfig>, ServerConfigStreamError>> + Send + Sync + Unpin + 'static
type ConfigStream: Stream<Item = Result<Arc<ServerConfig>, ServerConfigStreamError>> + Send + Sync + Unpin + 'static
The stream type produced by this builder.
Each item is either a fresh ServerConfig or an error explaining why
the update failed.
Required Methods§
Sourcefn build(
&mut self,
) -> impl Future<Output = Result<Self::ConfigStream, ServerConfigStreamError>> + Send
fn build( &mut self, ) -> impl Future<Output = Result<Self::ConfigStream, ServerConfigStreamError>> + Send
Asynchronously construct a new configuration stream.
The provider will:
- call this once during startup to obtain the initial stream,
- read the first config to seed its state,
- continue to poll the provided stream for new configs
- upon stream failure or completion, call it again with exponential backoff until a new stream is available.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.