Skip to content

Commit

Permalink
builder
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaydenr authored and rushilmehra committed Apr 8, 2024
1 parent 2cee0af commit 870ccd9
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions hyper-boring/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,14 @@ pub struct HttpsLayer {

/// Settings for [`HttpsLayer`]
pub struct HttpsLayerSettings {
/// Maximum number of sessions to cache. Session capacity is per session key (domain).
pub session_cache_capacity: usize,
session_cache_capacity: usize,
}

impl HttpsLayerSettings {
/// Constructs an [`HttpsLayerSettingsBuilder`] for configuring settings
pub fn builder() -> HttpsLayerSettingsBuilder {
HttpsLayerSettingsBuilder(HttpsLayerSettings::default())
}
}

impl Default for HttpsLayerSettings {
Expand All @@ -101,6 +107,22 @@ impl Default for HttpsLayerSettings {
}
}

/// Builder for [`HttpsLayerSettings`]
pub struct HttpsLayerSettingsBuilder(HttpsLayerSettings);

impl HttpsLayerSettingsBuilder {
/// Sets maximum number of sessions to cache. Session capacity is per session key (domain).
/// Defaults to 8.
pub fn set_session_cache_capacity(&mut self, capacity: usize) {
self.0.session_cache_capacity = capacity;
}

/// Consumes the builder, returning a new [`HttpsLayerSettings`]
pub fn build(self) -> HttpsLayerSettings {
self.0
}
}

impl HttpsLayer {
/// Creates a new `HttpsLayer` with default settings.
///
Expand Down

0 comments on commit 870ccd9

Please sign in to comment.