pub fn parse(source: &str, format: Option<&str>) -> Result<Value>
Expand description
Parse configuration from a string, auto-detecting format
This is the main entry point for parsing configuration data. The format is automatically detected based on the content structure and syntax.
§Arguments
source
- Configuration text to parseformat
- Optional format hint (auto-detected if None)
§Returns
Returns a Value
containing the parsed configuration data.
§Examples
use config_lib::parse;
let value = parse(r#"
app_name = "my-service"
port = 8080
debug = true
"#, Some("conf"))?;
// Access values from the parsed Value
if let Ok(table) = value.as_table() {
if let Some(app_name) = table.get("app_name") {
assert_eq!(app_name.as_string().unwrap(), "my-service");
}
if let Some(port) = table.get("port") {
assert_eq!(port.as_integer().unwrap(), 8080);
}
}