Extend TOML decoding with Toml.Transform
mainThe Toml.Transform behavior allows you to convert TOML values into custom Elixir types (like structs or specific data formats) during the decoding process.
Transforms are applied in the order provided using a depth-first, bottom-up traversal. This means leaf nodes (values) are transformed before their parent branches (tables/arrays).
# Example of a transform module
defmodule IPStringToCharlist do
use Toml.Transform
def transform(:ip, v) when is_binary(v) do
String.to_charlist(v)
end
def transform(_k, v), do: v
end
# Using transforms in decode
transforms = [IPStringToCharlist, ...]
{:ok, result} = Toml.decode("example.toml", keys: :atoms, transforms: transforms)