#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Config {
pub limit: Option<usize>,
pub variable_int_encoding: bool,
}
impl Config {
pub fn new() -> Self {
Self {
limit: None,
variable_int_encoding: true,
}
}
pub fn with_limit(mut self, limit: usize) -> Self {
self.limit = Some(limit);
self
}
pub fn with_variable_int_encoding(mut self, enabled: bool) -> Self {
self.variable_int_encoding = enabled;
self
}
}
impl Default for Config {
fn default() -> Self {
Self::new()
}
}
pub fn standard() -> Config {
Config::new()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_config_default() {
let config = Config::default();
assert_eq!(config.variable_int_encoding, true);
assert_eq!(config.limit, None);
}
#[test]
fn test_config_with_limit() {
let config = Config::new().with_limit(1024);
assert_eq!(config.limit, Some(1024));
}
#[test]
fn test_config_with_variable_int_encoding() {
let config = Config::new().with_variable_int_encoding(false);
assert_eq!(config.variable_int_encoding, false);
}
#[test]
fn test_standard_config() {
let config = standard();
assert_eq!(config.variable_int_encoding, true);
assert_eq!(config.limit, None);
}
#[test]
fn test_config_chaining() {
let config = Config::new()
.with_limit(1024)
.with_variable_int_encoding(false);
assert_eq!(config.limit, Some(1024));
assert_eq!(config.variable_int_encoding, false);
}
}