toml-parser-2.0.2.0: TOML 1.1.0 parser

Copyright | (c) Eric Mertens 2023
License | ISC
Maintainer | emertens@gmail.com
Safe Haskell | None
Language | Haskell2010

Toml.Schema.ToValue

Contents

- Table construction

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.

Synopsis

- class ToValue a where
  - toValue :: a -> Value
  - toValueList :: [a] -> Value
- class ToValue a => ToTable a where
  - toTable :: a -> Table
- class ToKey a where
  - toKey :: a -> Text
- defaultTableToValue :: ToTable a => a -> Value
- table :: [(Text, Value)] -> Table
- (.=) :: ToValue a => Text -> a -> (Text, Value)

# Documentation

class ToValue a where Source #

Class for types that can be embedded into `Value`

Minimal complete definition

toValue

Methods

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

Instances details

ToValue Int16 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int16 -> Value Source # toValueList :: [Int16] -> Value Source #
ToValue Int32 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int32 -> Value Source # toValueList :: [Int32] -> Value Source #
ToValue Int64 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int64 -> Value Source # toValueList :: [Int64] -> Value Source #
ToValue Int8 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int8 -> Value Source # toValueList :: [Int8] -> Value Source #
ToValue Word16 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word16 -> Value Source # toValueList :: [Word16] -> Value Source #
ToValue Word32 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word32 -> Value Source # toValueList :: [Word32] -> Value Source #
ToValue Word64 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word64 -> Value Source # toValueList :: [Word64] -> Value Source #
ToValue Word8 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word8 -> Value Source # toValueList :: [Word8] -> Value Source #
ToValue Text Source # | Encodes as string literal
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Text -> Value Source # toValueList :: [Text] -> Value Source #
ToValue Text Source # | Encodes as string literal
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Text -> Value Source # toValueList :: [Text] -> Value Source #
ToValue Day Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Day -> Value Source # toValueList :: [Day] -> Value Source #
ToValue UTCTime Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: UTCTime -> Value Source # toValueList :: [UTCTime] -> Value Source #
ToValue LocalTime Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: LocalTime -> Value Source # toValueList :: [LocalTime] -> Value Source #
ToValue TimeOfDay Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: TimeOfDay -> Value Source # toValueList :: [TimeOfDay] -> Value Source #
ToValue ZonedTime Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: ZonedTime -> Value Source # toValueList :: [ZonedTime] -> Value Source #
ToValue Value Source # | Identity function
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Value -> Value Source # toValueList :: [Value] -> Value Source #
ToValue Integer Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Integer -> Value Source # toValueList :: [Integer] -> Value Source #
ToValue Natural Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Natural -> Value Source # toValueList :: [Natural] -> Value Source #
ToValue Bool Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Bool -> Value Source # toValueList :: [Bool] -> Value Source #
ToValue Char Source # | Single characters are encoded as singleton strings. Lists of characters are encoded as a single string value.
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Char -> Value Source # toValueList :: [Char] -> Value Source #
ToValue Double Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Double -> Value Source # toValueList :: [Double] -> Value Source #
ToValue Float Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Float -> Value Source # toValueList :: [Float] -> Value Source #
ToValue Int Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int -> Value Source # toValueList :: [Int] -> Value Source #
ToValue Word Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word -> Value Source # toValueList :: [Word] -> Value Source #
ToValue a => ToValue (Seq a) Source # | Converts to list and encodes that to value
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Seq a -> Value Source # toValueList :: [Seq a] -> Value Source #
ToValue a => ToValue (NonEmpty a) Source # | Converts to list and encodes that to value
Instance details Defined in Toml.Schema.ToValue Methods toValue :: NonEmpty a -> Value Source # toValueList :: [NonEmpty a] -> Value Source #
Integral a => ToValue (Ratio a) Source # | TOML represents floating point numbers with `Double`. This operation lose precision and can overflow to infinity.
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Ratio a -> Value Source # toValueList :: [Ratio a] -> Value Source #
(Generic a, GToArray (Rep a)) => ToValue (GenericTomlArray a) Source # | Instance derived using `genericToArray`
Instance details Defined in Toml.Schema.Generic Methods toValue :: GenericTomlArray a -> Value Source # toValueList :: [GenericTomlArray a] -> Value Source #
(Generic a, GToTable (Rep a)) => ToValue (GenericTomlTable a) Source # | Instance derived from `ToTable` instance using `defaultTableToValue`
Instance details Defined in Toml.Schema.Generic Methods toValue :: GenericTomlTable a -> Value Source # toValueList :: [GenericTomlTable a] -> Value Source #
ToValue (Table' a) Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Table' a -> Value Source # toValueList :: [Table' a] -> Value Source #
ToValue a => ToValue [a] Source # | This instance defers to the list element's `toValueList` implementation.
Instance details Defined in Toml.Schema.ToValue Methods toValue :: [a] -> Value Source # toValueList :: [[a]] -> Value Source #
(ToKey k, ToValue v) => ToValue (Map k v) Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Map k v -> Value Source # toValueList :: [Map k v] -> Value Source #

# 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

Methods

toTable :: a -> Table Source #

Convert a single value into a table

#### Instances

Instances details

(Generic a, GToTable (Rep a)) => ToTable (GenericTomlTable a) Source # | Instance derived using `genericToTable`
Instance details Defined in Toml.Schema.Generic Methods toTable :: GenericTomlTable a -> Table Source #
ToTable (Table' a) Source # |
Instance details Defined in Toml.Schema.ToValue Methods toTable :: Table' a -> Table Source #
(ToKey k, ToValue v) => ToTable (Map k v) Source # |
Instance details Defined in Toml.Schema.ToValue Methods toTable :: Map k v -> Table Source #

class ToKey a where Source #

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.

Methods

toKey :: a -> Text Source #

#### Instances

Instances details

ToKey Text Source # |
Instance details Defined in Toml.Schema.ToValue Methods toKey :: Text -> Text Source #
ToKey Text Source # |
Instance details Defined in Toml.Schema.ToValue Methods toKey :: Text -> Text Source #
Char ~ a => ToKey [a] Source # |
Instance details Defined in Toml.Schema.ToValue Methods toKey :: [a] -> Text Source #

defaultTableToValue :: ToTable a => a -> Value Source #

Convenience function for building `ToValue` instances.

table :: [(Text, Value)] -> Table Source #

Build a `Table` from a list of key-value pairs.

Use `.=` for a convenient way to build the pairs.

(.=) :: ToValue a => Text -> a -> (Text, Value) Source #

Convenience function for building key-value pairs while constructing a `Table`.

    table [a .= b, c .= d]