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

Code before:

    /// Extend the current configuration with additional options.
    ///
    /// Parses the string and merges any enabled options into the current configuration.
    pub fn extend(&mut self, debug_string: String) -> Result<(), String> {
        let parsed = Self::parse_from_string(&debug_string)?;

        // Merge: any true value stays true
        self.help |= parsed.help;
        self.style_tree |= parsed.style_tree;
        self.rule_tree |= parsed.rule_tree;
        self.flow_tree |= parsed.flow_tree;
        self.stacking_context_tree |= parsed.stacking_context_tree;
        self.scroll_tree |= parsed.scroll_tree;
        self.display_list |= parsed.display_list;
        self.relayout_event |= parsed.relayout_event;
        self.profile_script_events |= parsed.profile_script_events;
        self.style_statistics |= parsed.style_statistics;
        self.gc_profile |= parsed.gc_profile;

        Ok(())
    }
}

impl Default for DiagnosticsLogging {
    fn default() -> Self {
        // Disabled for production builds
        #[cfg(debug_assertions)]
        {
            if let Ok(diagnostics_var) = std::env::var("SERVO_DIAGNOSTICS") {
                match Self::parse_from_string(&diagnostics_var) {
                    Ok(config) => return config,
                    Err(err) => {
                        println!("Warning: Failed to parse SERVO_DIAGNOSTICS: {}", err);
                    },
                }
            }
        }

        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,

Review comment (suggestion):
I would maybe implement `new()` instead of `default()` so you could avoid having to list the struct members below.

Code after:
                "relayout-event" => self.relayout_event = true,
                "" => {},
                _ => return Err(format!("Unknown diagnostic option: {option}")),
            };
        }

        Ok(())
    }
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum OutputOptions {
    /// Database connection config (hostname, name, user, pass)
    FileName(String),
    Stdout(f64),
}

impl Default for Opts {
    fn default() -> Self {
        Self {
            time_profiling: None,
            time_profiler_trace_path: None,
            nonincremental_layout: false,
            user_stylesheets: Vec::new(),
            hard_fail: true,
            multiprocess: false,
            force_ipc: false,
            background_hang_monitor: false,
            random_pipeline_closure_probability: None,
            random_pipeline_closure_seed: None,
            sandbox: false,
            debug: Default::default(),
            config_dir: None,
            shaders_path: None,
            certificate_path: None,
            ignore_certificate_errors: false,
            unminify_js: false,
            local_script_source: None,
            unminify_css: false,
            print_pwm: false,
        }
    }
}

// Make Opts available globally. This saves having to clone and pass
// opts everywhere it is used, which gets particularly cumbersome
// when passing through the DOM structures.
static OPTIONS: OnceLock<Opts> = OnceLock::new();

/// Initialize options.
///