| Copyright | (c) Eric Mertens 2023 |
|---|---|
| License | ISC |
| Maintainer | emertens@gmail.com |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Toml.Schema.FromValue
Description
Use FromValue to define a transformation from some Value to an application
domain type.
Use ParseTable to help build FromValue instances that match tables. It
will make it easy to track which table keys have been used and which are left
over.
Warnings can be emitted using warn and warnTable (depending on what)
context you're in. These warnings can provide useful feedback about
problematic values or keys that might be unused now but were perhaps
meaningful in an old version of a configuration file.
Toml.Schema.FromValue.Generic can be used to derive instances of FromValue
automatically for record types.
Synopsis
- class FromValue a where
- class FromKey a where
- mapOf :: Ord k => (l -> Text -> Matcher l k) -> (Text -> Value' l -> Matcher l v) -> Value' l -> Matcher l (Map k v)
- listOf :: (Int -> Value' l -> Matcher l a) -> Value' l -> Matcher l [a]
- parseTableFromValue :: ParseTable l a -> Value' l -> Matcher l a
- reqKey :: FromValue a => Text -> ParseTable l a
- reqKeyOf :: Text -> (Value' l -> Matcher l a) -> ParseTable l a
- optKey :: FromValue a => Text -> ParseTable l (Maybe a)
- optKeyOf :: Text -> (Value' l -> Matcher l a) -> ParseTable l (Maybe a)
- typeError :: String -> Value' l -> Matcher l a
Deserialization classes
class FromValue a where Source #
Class for types that can be decoded from a TOML value.
Minimal complete definition
Methods
fromValue :: Value' l -> Matcher l a Source #
Convert a Value or report an error message
listFromValue :: Value' l -> Matcher l [a] Source #
Used to implement instance for []. Most implementations rely on the default implementation.
Instances
| FromValue Int16 Source # | |
| FromValue Int32 Source # | |
| FromValue Int64 Source # | |
| FromValue Int8 Source # | |
| FromValue Word16 Source # | |
| FromValue Word32 Source # | |
| FromValue Word64 Source # | |
| FromValue Word8 Source # | |
| FromValue Text Source # | Matches string literals |
| FromValue Text Source # | Matches string literals |
| FromValue Day Source # | Matches local date literals |
| FromValue UTCTime Source # | Matches offset date-time literals and converts to UTC |
| FromValue LocalTime Source # | Matches local date-time literals |
| FromValue TimeOfDay Source # | Matches local time literals |
| FromValue ZonedTime Source # | Matches offset date-time literals |
| FromValue Table Source # | |
| FromValue Value Source # | Matches all values, used for pass-through |
| FromValue Integer Source # | Matches integer values |
| FromValue Natural Source # | Matches non-negative integer values |
| FromValue Bool Source # | Matches |
| FromValue Char Source # | Matches single-character strings with |
| FromValue Double Source # | Matches floating-point and integer values |
| FromValue Float Source # | Matches floating-point and integer values |
| FromValue Int Source # | |
| FromValue Word Source # | |
| FromValue a => FromValue (NonEmpty a) Source # | Matches non-empty arrays or reports an error. |
| Integral a => FromValue (Ratio a) Source # | Matches floating-point and integer values. TOML specifies |
| FromValue a => FromValue (Seq a) Source # | Matches arrays |
| (Generic a, GFromArray (Rep a)) => FromValue (GenericTomlArray a) Source # | Instance derived using |
Defined in Toml.Schema.Generic Methods fromValue :: Value' l -> Matcher l (GenericTomlArray a) Source # listFromValue :: Value' l -> Matcher l [GenericTomlArray a] Source # | |
| (Generic a, GParseTable (Rep a)) => FromValue (GenericTomlTable a) Source # | Instance derived using |
Defined in Toml.Schema.Generic Methods fromValue :: Value' l -> Matcher l (GenericTomlTable a) Source # listFromValue :: Value' l -> Matcher l [GenericTomlTable a] Source # | |
| FromValue a => FromValue [a] Source # | Implemented in terms of |
| (Ord k, FromKey k, FromValue v) => FromValue (Map k v) Source # | |
class FromKey a where Source #
Convert from a table key
Containers
Arguments
| :: Ord k | |
| => (l -> Text -> Matcher l k) | key matcher |
| -> (Text -> Value' l -> Matcher l v) | value matcher |
| -> Value' l | |
| -> Matcher l (Map k v) |
Table matching function used to help implement fromValue for tables.
Key matching function is given the annotation of the key for error reporting.
Value matching function is given the key in case values can depend on their keys.
listOf :: (Int -> Value' l -> Matcher l a) -> Value' l -> Matcher l [a] Source #
List matching function used to help implemented fromValue for arrays.
The element matching function is given the list index in case values can
depend on their index.
Tables
parseTableFromValue :: ParseTable l a -> Value' l -> Matcher l a Source #
Used to derive a fromValue implementation from a ParseTable matcher.
Arguments
| :: Text | key |
| -> (Value' l -> Matcher l a) | value matcher |
| -> ParseTable l a |
Match a table entry by key or report an error if missing.
See pickKey for more complex cases.
Arguments
| :: Text | key |
| -> (Value' l -> Matcher l a) | value matcher |
| -> ParseTable l (Maybe a) |