GitHub 仓库地址:https://github.com/fawdlstty/faml
什么是 FAML ?
FAML 是一种扩展自 TOML 的动态配置语言,专为需要运行时配置计算和更新的场景设计。它保留了 TOML 的简洁语法,同时增加了动态表达式、条件配置和运行时可变性等高级特性。
核心特性对比
| 特性 | TOML | KCL | PKL | FAML |
|---|---|---|---|---|
| 语法风格 | TOML 风格 | JSON 风格 | 结构体风格 | TOML 风格 |
| 动态表达式 | ||||
| 条件配置 | ||||
| 运行时修改 | ||||
| 特殊数据类型 |
快速示例
基本语法
[server] port = 8080 host = "localhost" 动态表达式
[database] host = "localhost" port = 5432 connection_string = $"postgresql://{host}:{port}/mydb" 条件配置
[app] env = "production" @if env == "development" log_level = "debug" @if env == "production" log_level = "error" 特殊数据类型
[cache] ttl = 5 minutes max_size = 100 MB [network] timeout = 30 seconds buffer_size = 4 KB 复杂表达式
[user] age = 25 is_adult = age >=18 welcome_message = is_adult ? $"Welcome, adult user!" : $"Welcome, young user!" 运行时动态修改
let mut cOnfig= FamlExpr::from_str(config_str)?; config["server"]["port"].set_int(9000); // 动态修改端口 let connection_string = config["database"]["connection_string"].evaluate()?.as_str(); // 自动更新连接字符串 