pub trait ConfigFormat: Send + Sync {
// Required methods
fn extensions(&self) -> &[&str];
fn parse(&self, contents: &str) -> Result<ConfigValue, ConfigFormatError>;
}Expand description
Trait for config file format parsers.
Implementations of this trait can parse configuration files into ConfigValue,
preserving source span information for rich error messages.
§Built-in Formats
JsonFormat- JSON files (.json)
§Custom Formats
To support additional formats (TOML, YAML, etc.), implement this trait:
ⓘ
use figue::config_format::{ConfigFormat, ConfigFormatError};
use figue::config_value::ConfigValue;
pub struct TomlFormat;
impl ConfigFormat for TomlFormat {
fn extensions(&self) -> &[&str] {
&["toml"]
}
fn parse(&self, contents: &str) -> Result<ConfigValue, ConfigFormatError> {
// Parse TOML and convert to ConfigValue with spans...
todo!()
}
}Required Methods§
Sourcefn extensions(&self) -> &[&str]
fn extensions(&self) -> &[&str]
File extensions this format handles (without the leading dot).
For example, ["json"] or ["yaml", "yml"].
Sourcefn parse(&self, contents: &str) -> Result<ConfigValue, ConfigFormatError>
fn parse(&self, contents: &str) -> Result<ConfigValue, ConfigFormatError>
Parse file contents into a ConfigValue with span tracking.
The implementation should preserve source locations in the returned
ConfigValue tree so that error messages can point to the exact
location in the config file.