GitHub 仓库地址:https://github.com/fawdlstty/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(); // 自动更新连接字符串
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.