sword_layers/compression/
config.rs

1use console::style;
2use serde::{Deserialize, Serialize};
3
4use crate::DisplayConfig;
5
6/// ### Compression Configuration
7/// Configuration for the Compression Layer
8/// This configuration allows you to enable or disable compression
9/// and specify which algorithms to use.
10///
11/// #### Fields:
12/// - `enabled`: A boolean indicating if compression is enabled.
13/// - `algorithms`: A list of strings representing the compression algorithms to use
14/// (e.g., "gzip", "deflate", "br", "zstd")
15///
16/// - `display`: A boolean indicating if the configuration should be displayed.
17#[derive(Debug, Clone, Deserialize, Serialize, Default)]
18pub struct CompressionConfig {
19    #[serde(default)]
20    pub enabled: bool,
21
22    #[serde(default)]
23    pub algorithms: Vec<String>,
24
25    #[serde(default)]
26    pub display: bool,
27}
28
29impl DisplayConfig for CompressionConfig {
30    fn display(&self) {
31        if !self.display {
32            return;
33        }
34
35        println!("\n{}", style("Compression Configuration:").bold());
36
37        if self.enabled {
38            if self.algorithms.is_empty() {
39                println!("  ↳  {}", style("No algorithms enabled").yellow());
40            } else {
41                println!("  ↳  Algorithms: {}", self.algorithms.join(", "));
42            }
43        } else {
44            println!("  ↳  {}", style("Compression: disabled").red());
45        }
46    }
47}