Skip to main content

Config

Struct Config 

Source
pub struct Config {
    pub features: FeaturesConfig,
    pub style: StyleConfig,
}
Expand description

Main configuration structure.

Contains all configuration sections for streamdown.

Fields§

§features: FeaturesConfig

Feature flags configuration

§style: StyleConfig

Style configuration

Implementations§

Source§

impl Config

Source

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]"));
Source

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());
}
Source

pub fn config_dir() -> Option<PathBuf>

Returns the platform-specific configuration directory.

Source

pub fn ensure_config_file() -> Result<PathBuf>

Ensures the config file exists, creating it with defaults if not.

This mirrors the Python ensure_config_file function.

§Returns

The path to the config file.

§Example
use streamdown_config::Config;
let path = Config::ensure_config_file().unwrap();
assert!(path.exists());
Source

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();
Source

pub fn load_from(path: &Path) -> Result<Self>

Load configuration from a specific path.

§Arguments
  • path - Path to the TOML configuration file
§Example
use streamdown_config::Config;
use std::path::Path;
let config = Config::load_from(Path::new("./config.toml")).unwrap();
Source

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:

  1. Load the base config from the default location
  2. 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();
Source

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);
Source

pub fn save_to(&self, path: &Path) -> Result<()>

Save configuration to a file.

§Arguments
  • path - Path to save the configuration to
Source

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());

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Config

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Config

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,