#[derive(Debug, Clone)]
pub struct GrpcConfig {
pub max_message_size: usize,
pub concurrency_limit: usize,
pub stream_channel_capacity: usize,
}
impl Default for GrpcConfig {
fn default() -> Self {
Self {
max_message_size: 4 * 1024 * 1024,
concurrency_limit: 256,
stream_channel_capacity: 64,
}
}
}
impl GrpcConfig {
#[must_use]
pub const fn with_max_message_size(mut self, size: usize) -> Self {
self.max_message_size = size;
self
}
#[must_use]
pub const fn with_concurrency_limit(mut self, limit: usize) -> Self {
self.concurrency_limit = limit;
self
}
#[must_use]
pub const fn with_stream_channel_capacity(mut self, capacity: usize) -> Self {
self.stream_channel_capacity = capacity;
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn grpc_config_default_values() {
let config = GrpcConfig::default();
assert_eq!(config.max_message_size, 4 * 1024 * 1024);
assert_eq!(config.concurrency_limit, 256);
assert_eq!(config.stream_channel_capacity, 64);
}
#[test]
fn grpc_config_builders() {
let config = GrpcConfig::default()
.with_max_message_size(8 * 1024 * 1024)
.with_concurrency_limit(128)
.with_stream_channel_capacity(32);
assert_eq!(config.max_message_size, 8 * 1024 * 1024);
assert_eq!(config.concurrency_limit, 128);
assert_eq!(config.stream_channel_capacity, 32);
}
}