fiction/providers/toml
Values
pub fn file(
path: String,
) -> fn() -> Result(List(#(String, fiction.Value)), String)
Read a TOML file at path and parse it into fiction.Values
This function currently panics if the TOML file contains any infinities or NaNs
Example
import gleam/dynamic/decode
import fiction
import fiction/providers/toml
type Foo {
Foo(bar: String)
}
fn foo_decoder() {
use bar <- decode.then(decode.at(["tools", "example", "bar"], decode.string))
decode.success(Foo(bar:))
}
pub fn main() {
let assert Ok(foo) =
fiction.new()
|> fiction.join(toml.file("./gleam.toml"))
|> fiction.extract(foo_decoder())
assert foo.bar == "baz"
}