Toml.ToValue

toml-parser-1.3.0.0: TOML 1.0.0 parser

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

Toml.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 from a `Table`.

Toml.ToValue.Generic can be used to derive instances of `ToTable` automatically for record 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 -> String
- defaultTableToValue :: ToTable a => a -> Value
- table :: [(String, Value)] -> Table
- (.=) :: ToValue a => String -> a -> (String, Value)

# Documentation

class ToValue a where #

Class for types that can be embedded into `Value`

Minimal complete definition

toValue

Methods

toValue :: a -> Value #

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

Instances details

ToValue Int16 # |
Instance details Defined in Toml.ToValue Methods toValue :: Int16 -> Value # toValueList :: [Int16] -> Value #
ToValue Int32 # |
Instance details Defined in Toml.ToValue Methods toValue :: Int32 -> Value # toValueList :: [Int32] -> Value #
ToValue Int64 # |
Instance details Defined in Toml.ToValue Methods toValue :: Int64 -> Value # toValueList :: [Int64] -> Value #
ToValue Int8 # |
Instance details Defined in Toml.ToValue Methods toValue :: Int8 -> Value # toValueList :: [Int8] -> Value #
ToValue Word16 # |
Instance details Defined in Toml.ToValue Methods toValue :: Word16 -> Value # toValueList :: [Word16] -> Value #
ToValue Word32 # |
Instance details Defined in Toml.ToValue Methods toValue :: Word32 -> Value # toValueList :: [Word32] -> Value #
ToValue Word64 # |
Instance details Defined in Toml.ToValue Methods toValue :: Word64 -> Value # toValueList :: [Word64] -> Value #
ToValue Word8 # |
Instance details Defined in Toml.ToValue Methods toValue :: Word8 -> Value # toValueList :: [Word8] -> Value #
ToValue Text # | Encodes as string literal Since: 1.2.1.0
Instance details Defined in Toml.ToValue Methods toValue :: Text -> Value # toValueList :: [Text] -> Value #
ToValue Text # | Encodes as string literal Since: 1.2.1.0
Instance details Defined in Toml.ToValue Methods toValue :: Text -> Value # toValueList :: [Text] -> Value #
ToValue Day # |
Instance details Defined in Toml.ToValue Methods toValue :: Day -> Value # toValueList :: [Day] -> Value #
ToValue LocalTime # |
Instance details Defined in Toml.ToValue Methods toValue :: LocalTime -> Value # toValueList :: [LocalTime] -> Value #
ToValue TimeOfDay # |
Instance details Defined in Toml.ToValue Methods toValue :: TimeOfDay -> Value # toValueList :: [TimeOfDay] -> Value #
ToValue ZonedTime # |
Instance details Defined in Toml.ToValue Methods toValue :: ZonedTime -> Value # toValueList :: [ZonedTime] -> Value #
ToValue Value # | Identity function
Instance details Defined in Toml.ToValue Methods toValue :: Value -> Value # toValueList :: [Value] -> Value #
ToValue Integer # |
Instance details Defined in Toml.ToValue Methods toValue :: Integer -> Value # toValueList :: [Integer] -> Value #
ToValue Natural # |
Instance details Defined in Toml.ToValue Methods toValue :: Natural -> Value # toValueList :: [Natural] -> Value #
ToValue Bool # |
Instance details Defined in Toml.ToValue Methods toValue :: Bool -> Value # toValueList :: [Bool] -> Value #
ToValue Char # | Single characters are encoded as singleton strings. Lists of characters are encoded as a single string value.
Instance details Defined in Toml.ToValue Methods toValue :: Char -> Value # toValueList :: [Char] -> Value #
ToValue Double # |
Instance details Defined in Toml.ToValue Methods toValue :: Double -> Value # toValueList :: [Double] -> Value #
ToValue Float # |
Instance details Defined in Toml.ToValue Methods toValue :: Float -> Value # toValueList :: [Float] -> Value #
ToValue Int # |
Instance details Defined in Toml.ToValue Methods toValue :: Int -> Value # toValueList :: [Int] -> Value #
ToValue Word # |
Instance details Defined in Toml.ToValue Methods toValue :: Word -> Value # toValueList :: [Word] -> Value #
ToValue a => ToValue (NonEmpty a) # | Converts to list and encodes that to value Since: 1.3.0.0
Instance details Defined in Toml.ToValue Methods toValue :: NonEmpty a -> Value # toValueList :: [NonEmpty a] -> Value #
Integral a => ToValue (Ratio a) # | Converts to a `Double`. This can overflow to infinity. Since: 1.3.0.0
Instance details Defined in Toml.ToValue Methods toValue :: Ratio a -> Value # toValueList :: [Ratio a] -> Value #
ToValue a => ToValue (Seq a) # | Converts to list and encodes that to value Since: 1.3.0.0
Instance details Defined in Toml.ToValue Methods toValue :: Seq a -> Value # toValueList :: [Seq a] -> Value #
ToValue a => ToValue [a] # | This instance defers to the list element's `toValueList` implementation.
Instance details Defined in Toml.ToValue Methods toValue :: [a] -> Value # toValueList :: [[a]] -> Value #
(ToKey k, ToValue v) => ToValue (Map k v) # | Since: 1.0.1.0
Instance details Defined in Toml.ToValue Methods toValue :: Map k v -> Value # toValueList :: [Map k v] -> Value #

# Table construction

class ToValue a => ToTable a where #

Class for things that can be embedded into a TOML table.

Implement this for things that embed into a `Table` and then the `ToValue` instance can be derived with `defaultTableToValue`.

Methods

toTable :: a -> Table #

Convert a single value into a table

#### Instances

Instances details

(ToKey k, ToValue v) => ToTable (Map k v) # | Since: 1.0.1.0
Instance details Defined in Toml.ToValue Methods toTable :: Map k v -> Table #

class ToKey a where #

Convert to a table key

Since: 1.3.0.0

Methods

toKey :: a -> String #

#### Instances

Instances details

ToKey Text # | toKey = unpack Since: 1.3.0.0
Instance details Defined in Toml.ToValue Methods toKey :: Text -> String #
ToKey Text # | toKey = unpack Since: 1.3.0.0
Instance details Defined in Toml.ToValue Methods toKey :: Text -> String #
Char ~ a => ToKey [a] # | toKey = id Since: 1.3.0.0
Instance details Defined in Toml.ToValue Methods toKey :: [a] -> String #

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

Convenience function for building `ToValue` instances.

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

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

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

Since: 1.3.0.0

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

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

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