pub struct Config {
pub features: FeaturesConfig,
pub style: StyleConfig,
}Expand description
Main configuration structure.
Contains all configuration sections for streamdown.
Fields§
§features: FeaturesConfigFeature flags configuration
style: StyleConfigStyle configuration
Implementations§
Source§impl Config
impl Config
Sourcepub fn default_toml() -> &'static str
pub fn default_toml() -> &'static str
Returns the default TOML configuration string.
This can be used to show users the default config or to write a default config file.
§Example
use streamdown_config::Config;
let toml = Config::default_toml();
assert!(toml.contains("[features]"));
assert!(toml.contains("[style]"));Sourcepub fn config_path() -> Option<PathBuf>
pub fn config_path() -> Option<PathBuf>
Returns the platform-specific configuration file path.
§Example
use streamdown_config::Config;
if let Some(path) = Config::config_path() {
println!("Config path: {}", path.display());
}Sourcepub fn config_dir() -> Option<PathBuf>
pub fn config_dir() -> Option<PathBuf>
Returns the platform-specific configuration directory.
Sourcepub fn ensure_config_file() -> Result<PathBuf>
pub fn ensure_config_file() -> Result<PathBuf>
Sourcepub fn load() -> Result<Self>
pub fn load() -> Result<Self>
Load configuration from the default platform-specific path.
If no config file exists, returns the default configuration.
§Example
use streamdown_config::Config;
let config = Config::load().unwrap();Sourcepub fn load_with_override(override_config: Option<&str>) -> Result<Self>
pub fn load_with_override(override_config: Option<&str>) -> Result<Self>
Load configuration with an optional override file or string.
This mirrors the Python ensure_config_file behavior:
- Load the base config from the default location
- If override_path is provided:
- If it’s a path to an existing file, load and merge it
- Otherwise, treat it as a TOML string and parse it
§Arguments
override_config- Optional path to override file or inline TOML string
§Example
use streamdown_config::Config;
// Load with file override
let config = Config::load_with_override(Some("./custom.toml".as_ref())).unwrap();
// Load with inline TOML override
let config = Config::load_with_override(Some("[features]\nLinks = false".as_ref())).unwrap();Sourcepub fn merge(&mut self, other: &Config)
pub fn merge(&mut self, other: &Config)
Merge another config into this one.
Values from other take precedence over values in self.
This is used for applying CLI overrides or secondary config files.
§Arguments
other- The config to merge from
§Example
use streamdown_config::Config;
let mut base = Config::default();
let override_config: Config = toml::from_str(r#"
[features]
Links = false
"#).unwrap();
base.merge(&override_config);
assert!(!base.features.links);Sourcepub fn computed_style(&self) -> ComputedStyle
pub fn computed_style(&self) -> ComputedStyle
Compute the style values (ANSI codes) from this config.
This applies the HSV multipliers to generate actual ANSI color codes.
§Example
use streamdown_config::Config;
let config = Config::default();
let computed = config.computed_style();
assert!(!computed.dark.is_empty());