use std::collections::HashMap;
use std::io;
#[derive(Debug, Clone)]
pub struct Config {
pub name: String,
pub port: u16,
pub enabled: bool,
}
impl Config {
pub fn new(name: &str) -> Self {
Self {
name: name.to_string(),
port: 8080,
enabled: true,
}
}
}
fn main() -> io::Result<()> {
let config = Config::new("batless");
let mut cache: HashMap<String, Vec<u8>> = HashMap::new();
for i in 0..10 {
let key = format!("item_{}", i);
let value = vec![i as u8; i];
cache.insert(key, value);
}
println!("Configuration: {:?}", config);
println!("Cache size: {}", cache.len());
if config.enabled {
process_data(&cache)?;
} else {
eprintln!("Processing disabled!");
}
Ok(())
}
fn process_data(cache: &HashMap<String, Vec<u8>>) -> io::Result<()> {
for (key, value) in cache.iter() {
println!("Key: {}, Value size: {}", key, value.len());
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_config_creation() {
let config = Config::new("test");
assert_eq!(config.name, "test");
assert_eq!(config.port, 8080);
assert!(config.enabled);
}
}