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 Table
.
Toml.ToValue.Generic can be used to derive instances of ToTable
automatically for record types.
Synopsis
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 Table
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
Instances
(Generic a, GToTable (Rep a)) => ToTable (GenericTomlTable a) Source # | Instance derived using |
Defined in Toml.Generic toTable :: GenericTomlTable a -> Table Source # | |
(ToKey k, ToValue v) => ToTable (Map k v) Source # | Since: 1.0.1.0 |
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.
Since: 1.3.0.0
defaultTableToValue :: ToTable a => a -> Value Source #
Convenience function for building ToValue
instances.