Copyright | (c) Eric Mertens 2024 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module makes it possible to easily derive the TOML classes
using the DerivingVia
extension.
For example:
data Physical = Physical { color :: String, shape :: String } deriving (Eq, Show, Generic) deriving (ToTable, ToValue, FromValue) via GenericTomlTable Physical
These derived instances would allow you to match TOML
{color="red", shape="round"}
to value Physical "red" "round"
.
data Coord = Coord Int Int deriving (Eq, Show, Generic) deriving (ToValue, FromValue) via GenericTomlArray Physical
These derived instances would allow you to match TOML [1,2]
to value Coord 1 2
.
Synopsis
- newtype GenericTomlTable a = GenericTomlTable a
- newtype GenericTomlArray a = GenericTomlArray a
- genericFromArray :: (Generic a, GFromArray (Rep a)) => Value' l -> Matcher l a
- genericFromTable :: (Generic a, GParseTable (Rep a)) => Value' l -> Matcher l a
- class GFromArray f
- class GParseTable f
- genericToArray :: (Generic a, GToArray (Rep a)) => a -> Value
- genericToTable :: (Generic a, GToTable (Rep a)) => a -> Table
- class GToArray f
- class GToTable f
DerivingVia
newtype GenericTomlTable a Source #
Instances
(Generic a, GParseTable (Rep a)) => FromValue (GenericTomlTable a) Source # | Instance derived using |
Defined in Toml.Schema.Generic fromValue :: Value' l -> Matcher l (GenericTomlTable a) Source # listFromValue :: Value' l -> Matcher l [GenericTomlTable a] Source # | |
(Generic a, GToTable (Rep a)) => ToTable (GenericTomlTable a) Source # | Instance derived using |
Defined in Toml.Schema.Generic toTable :: GenericTomlTable a -> Table Source # | |
(Generic a, GToTable (Rep a)) => ToValue (GenericTomlTable a) Source # | Instance derived from |
Defined in Toml.Schema.Generic toValue :: GenericTomlTable a -> Value Source # toValueList :: [GenericTomlTable a] -> Value Source # |
newtype GenericTomlArray a Source #
Helper type to use GHC's DerivingVia extension to derive
ToValue
, ToTable
, FromValue
for any product type.
Instances
(Generic a, GFromArray (Rep a)) => FromValue (GenericTomlArray a) Source # | Instance derived using |
Defined in Toml.Schema.Generic fromValue :: Value' l -> Matcher l (GenericTomlArray a) Source # listFromValue :: Value' l -> Matcher l [GenericTomlArray a] Source # | |
(Generic a, GToArray (Rep a)) => ToValue (GenericTomlArray a) Source # | Instance derived using |
Defined in Toml.Schema.Generic toValue :: GenericTomlArray a -> Value Source # toValueList :: [GenericTomlArray a] -> Value Source # |
FromValue
genericFromArray :: (Generic a, GFromArray (Rep a)) => Value' l -> Matcher l a Source #
Match a Value'
as an array positionally matching field fields
of a constructor to the elements of the array.
genericFromTable :: (Generic a, GParseTable (Rep a)) => Value' l -> Matcher l a Source #
Implementation of fromValue
using genericParseTable
to derive
a match from the record field names of the target type.
class GFromArray f Source #
Supports conversion of TOML arrays into product-type values.
Instances
GFromArray (U1 :: Type -> Type) Source # | Uses no array elements |
Defined in Toml.Schema.Generic.FromValue | |
(GFromArray f, GFromArray g) => GFromArray (f :*: g) Source # | |
Defined in Toml.Schema.Generic.FromValue | |
FromValue a => GFromArray (K1 i a :: Type -> Type) Source # | |
Defined in Toml.Schema.Generic.FromValue | |
GFromArray f => GFromArray (M1 i c f) Source # | |
Defined in Toml.Schema.Generic.FromValue |
class GParseTable f Source #
Supports conversion of TOML tables into record values using field selector names as TOML keys.
Instances
ToValue
genericToArray :: (Generic a, GToArray (Rep a)) => a -> Value Source #
Use a record's field names to generate a Value'
genericToTable :: (Generic a, GToTable (Rep a)) => a -> Table Source #
Use a record's field names to generate a Value'
Convert product types to arrays positionally.
Supports conversion of product types with field selector names to TOML values.
Instances
GToTable (U1 :: Type -> Type) Source # | Emits empty table |
GToTable (V1 :: Type -> Type) Source # | |
(GToTable f, GToTable g) => GToTable (f :*: g) Source # | |
GToTable f => GToTable (C1 c f) Source # | Ignores value constructor names |
GToTable f => GToTable (D1 c f) Source # | Ignores type constructor names |
(Selector s, ToValue a) => GToTable (S1 s (K1 i (Maybe a) :: Type -> Type)) Source # | Omits the key from the table on nothing, includes it on just |
(Selector s, ToValue a) => GToTable (S1 s (K1 i a :: Type -> Type)) Source # | Uses record selector name as table key |