Copyright | (c) Eric Mertens 2023 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
The ToValue
class provides a conversion function from
application-specific to TOML values.
Because the top-level TOML document is always a table,
the ToTable
class is for types that specifically support
conversion to a Value'
.
Toml.Schema.Generic can be used to derive instances of ToTable
automatically for record types and ToValue
for array types.
Documentation
class ToValue a where Source #
Class for types that can be embedded into Value
toValue :: a -> Value Source #
Embed a single thing into a TOML value.
toValueList :: [a] -> Value Source #
Helper for converting a list of things into a value. This is typically left to be defined by its default implementation and exists to help define the encoding for TOML arrays.
Instances
Table construction
class ToValue a => ToTable a where Source #
Class for things that can be embedded into a TOML table.
Implement this for things that always embed into a Value'
and then
the ToValue
instance can be derived with defaultTableToValue
.
instance ToValue Example where toValue = defaultTableToValue -- Option 1: Manual instance instance ToTable Example where toTable x =table
["field1".=
field1 x, "field2".=
field2 x] -- Option 2: GHC.Generics derived instance using Toml.ToValue.Generic instance ToTable Example where toTable = genericToTable
Convert to a table key. This class enables various string types to be
used as the keys of a Map
when converting into TOML tables.
defaultTableToValue :: ToTable a => a -> Value Source #
Convenience function for building ToValue
instances.