Skip to main content

sword_layers/compression/
config.rs

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