grimoire_css_lib/core/
css_optimizer.rs

1//! This module defines the `CssOptimizer` trait, which provides an interface for optimizing raw CSS.
2//!
3//! Implementations of this trait are responsible for taking raw CSS input and producing optimized,
4//! minified output. The specific optimization techniques are left to the implementation details.
5//! This trait allows for different optimization backends to be easily swapped or replaced within the system.
6
7use super::GrimoireCssError;
8
9/// The `CssOptimizer` trait provides an interface for optimizing CSS.
10///
11/// This trait is designed to be implemented by different CSS optimization engines. Implementations
12/// of this trait can apply various techniques to minify, clean up, or otherwise optimize raw CSS code.
13///
14/// # Example
15///
16/// ```ignore
17/// struct MyOptimizer;
18///
19/// impl CssOptimizer for MyOptimizer {
20///     fn optimize(&self, raw_css: &str) -> Result<String, GrimoireCSSError> {
21///         // Perform optimization here
22///         Ok(minified_css)
23///     }
24/// }
25/// ```
26///
27/// # Errors
28///
29/// This method returns a `GrimoireCSSError` if the optimization process fails for any reason.
30pub trait CssOptimizer: Sync + Send {
31    /// Optimizes a given raw CSS string and returns the optimized result.
32    ///
33    /// # Arguments
34    ///
35    /// * `raw_css` - A string containing the raw CSS code that needs to be optimized.
36    ///
37    /// # Returns
38    ///
39    /// * `Ok(String)` - The optimized and minified CSS string.
40    /// * `Err(GrimoireCSSError)` - An error indicating that the optimization process failed.
41    fn optimize(&self, raw_css: &str) -> Result<String, GrimoireCssError>;
42}