| Copyright | (c) Eric Mertens 2023 |
|---|---|
| License | ISC |
| Maintainer | emertens@gmail.com |
| Safe Haskell | None |
| 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 for types that can be decoded from a TOML value.
Minimal complete definition
Methods
fromValue :: Value' l -> Matcher l a #
Convert a Value or report an error message
listFromValue :: Value' l -> Matcher l [a] #
Used to implement instance for []. Most implementations rely on the default implementation.
Instances
| FromValue Int16 # | |
| FromValue Int32 # | |
| FromValue Int64 # | |
| FromValue Int8 # | |
| FromValue Word16 # | |
| FromValue Word32 # | |
| FromValue Word64 # | |
| FromValue Word8 # | |
| FromValue Text # | Matches string literals |
| FromValue Text # | Matches string literals |
| FromValue Day # | Matches local date literals |
| FromValue LocalTime # | Matches local date-time literals |
| FromValue TimeOfDay # | Matches local time literals |
| FromValue ZonedTime # | Matches offset date-time literals |
| FromValue Table # | |
| FromValue Value # | Matches all values, used for pass-through |
| FromValue Integer # | Matches integer values |
| FromValue Natural # | Matches non-negative integer values |
| FromValue Bool # | Matches |
| FromValue Char # | Matches single-character strings with |
| FromValue Double # | Matches floating-point and integer values |
| FromValue Float # | Matches floating-point and integer values |
| FromValue Int # | |
| FromValue Word # | |
| FromValue a => FromValue (NonEmpty a) # | Matches non-empty arrays or reports an error. |
| Integral a => FromValue (Ratio a) # | Matches floating-point and integer values. TOML specifies |
| FromValue a => FromValue (Seq a) # | Matches arrays |
| (Generic a, GFromArray (Rep a)) => FromValue (GenericTomlArray a) # | Instance derived using |
Defined in Toml.Schema.Generic Methods fromValue :: Value' l -> Matcher l (GenericTomlArray a) # listFromValue :: Value' l -> Matcher l [GenericTomlArray a] # | |
| (Generic a, GParseTable (Rep a)) => FromValue (GenericTomlTable a) # | Instance derived using |
Defined in Toml.Schema.Generic Methods fromValue :: Value' l -> Matcher l (GenericTomlTable a) # listFromValue :: Value' l -> Matcher l [GenericTomlTable a] # | |
| FromValue a => FromValue [a] # | Implemented in terms of |
Defined in Toml.Schema.FromValue | |
| (Ord k, FromKey k, FromValue v) => FromValue (Map k v) # | |
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] #
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 #
Used to derive a fromValue implementation from a ParseTable matcher.
reqKey :: FromValue a => Text -> ParseTable l a #
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) |