Repository: servo/servo
File: components/config/opts.rs (Rust)

Code before:
    /// Shows hit/miss statistics for the style sharing cache
    pub style_statistics: bool,

    /// Log garbage collection passes and their durations.
    pub gc_profile: bool,
}

impl DiagnosticsLogging {
    /// Parse diagnostic options from a comma-separated string.
    ///
    /// Returns a configured `DiagnosticsLogging` instance. If the string contains
    /// "help", this will print available options and exit the program.
    pub fn parse_from_string(options_string: &str) -> Result<Self, String> {
        let mut config = Self {
            help: false,
            style_tree: false,
            rule_tree: false,
            flow_tree: false,
            stacking_context_tree: false,
            scroll_tree: false,
            display_list: false,
            relayout_event: false,
            profile_script_events: false,
            style_statistics: false,
            gc_profile: false,
        };

        for option in options_string.split(',') {
            let option = option.trim();
            match option {
                "help" => config.help = true,
                "display-list" => config.display_list = true,
                "stacking-context-tree" => config.stacking_context_tree = true,
                "flow-tree" => config.flow_tree = true,
                "rule-tree" => config.rule_tree = true,
                "style-tree" => config.style_tree = true,
                "style-stats" => config.style_statistics = true,
                "scroll-tree" => config.scroll_tree = true,
                "gc-profile" => config.gc_profile = true,
                "profile-script-events" => config.profile_script_events = true,
                "relayout-event" => config.relayout_event = true,
                "" => {},
                _ => return Err(format!("Unknown diagnostic option: {}", option)),
            };
        }

        Ok(config)
    }

    /// Print available diagnostic logging options and their descriptions.
    pub fn print_debug_options_usage(app: &str) {

Review comment (suggestion):
If you re-add the`Default` implementation for `DiagnosticsLogging` this can just be:


```suggestion
        let mut config = Default::default();
```

Code after:
    ///
    /// Shows hit/miss statistics for the style sharing cache
    pub style_statistics: bool,

    /// Log garbage collection passes and their durations.
    pub gc_profile: bool,
}

impl DiagnosticsLogging {
    /// Create a new DiagnosticsLogging configuration.
    ///
    /// In non-production builds, this will automatically read and parse the
    /// SERVO_DIAGNOSTICS environment variable if it is set.
    pub fn new() -> Self {
        let mut config: DiagnosticsLogging = Default::default();

        // Disabled for production builds
        #[cfg(debug_assertions)]
        {
            if let Ok(diagnostics_var) = std::env::var("SERVO_DIAGNOSTICS") {
                if let Err(error) = config.extend_from_string(&diagnostics_var) {
                    eprintln!("Could not parse debug logging option: {error}");
                }
            }
        }

        config
    }

    /// Print available diagnostic logging options and their descriptions.
    fn print_debug_options_usage(app: &str) {
        fn print_option(name: &str, description: &str) {
            println!("\t{:<35} {}", name, description);
        }

        println!(
            "Usage: {} debug option,[options,...]\n\twhere options include\n\nOptions:",
            app
        );
        print_option("help", "Show this help message");
        print_option("style-tree", "Log the style tree after each restyle");
        print_option("rule-tree", "Log the rule tree");
        print_option("flow-tree", "Log the fragment tree after each layout");
        print_option(
            "stacking-context-tree",
            "Log the stacking context tree after each layout",
        );
        print_option("scroll-tree", "Log the scroll tree after each layout");
        print_option("display-list", "Log the display list after each layout");
        print_option("style-stats", "Log style sharing cache statistics");
        print_option("relayout-event", "Log when relayout occurs");