| Copyright | (c) Eric Mertens 2023 |
|---|---|
| License | ISC |
| Maintainer | emertens@gmail.com |
| Safe Haskell | None |
| Language | Haskell2010 |
Toml.Schema.ToValue
Contents
Description
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.Schema.Generic can be used to derive instances of ToTable
automatically for record types and ToValue for array types.
Documentation
Class for types that can be embedded into Value
Minimal complete definition
Methods
Embed a single thing into a TOML value.
toValueList :: [a] -> Value #
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 #
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) # | Instance derived using |
Defined in Toml.Schema.Generic Methods toTable :: GenericTomlTable a -> Table # | |
| ToTable (Table' a) # | |
Defined in Toml.Schema.ToValue | |
| (ToKey k, ToValue v) => ToTable (Map k v) # | |
Defined in Toml.Schema.ToValue | |
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 #
Convenience function for building ToValue instances.