Skip to content
Snippets Groups Projects
Verified Commit 430471e8 authored by jan.hamal.dvorak's avatar jan.hamal.dvorak
Browse files

Add ToParam class

parent 9eee7ce2
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ This module provides types common for multiple other modules. ...@@ -12,6 +12,7 @@ This module provides types common for multiple other modules.
module Web.Hikaru.Types module Web.Hikaru.Types
( FromParam(..) ( FromParam(..)
, ToParam(..)
, RequestError(..) , RequestError(..)
, defaultHandler , defaultHandler
) )
...@@ -20,7 +21,7 @@ where ...@@ -20,7 +21,7 @@ where
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
import Data.String.Conversions import Data.String.Conversions
import Data.Text (Text, unpack) import Data.Text (Text, pack, unpack)
import Network.HTTP.Types.Status import Network.HTTP.Types.Status
import Network.HTTP.Types.Header import Network.HTTP.Types.Header
import Network.Wai import Network.Wai
...@@ -107,6 +108,79 @@ where ...@@ -107,6 +108,79 @@ where
fromParam = Just . cs fromParam = Just . cs
-- |
-- Values that can be represented as a piece of 'Text' to be used in a
-- route segment or a query string. One does not usually pass around
-- more complex arguments than these, so forgive the limited menu.
--
class ToParam a where
toParam :: a -> Text
instance ToParam Int where
toParam = pack . show
instance ToParam Int8 where
toParam = pack . show
instance ToParam Int16 where
toParam = pack . show
instance ToParam Int32 where
toParam = pack . show
instance ToParam Int64 where
toParam = pack . show
instance ToParam Word where
toParam = pack . show
instance ToParam Word8 where
toParam = pack . show
instance ToParam Word16 where
toParam = pack . show
instance ToParam Word32 where
toParam = pack . show
instance ToParam Word64 where
toParam = pack . show
instance ToParam Integer where
toParam = pack . show
instance ToParam Natural where
toParam = pack . show
instance ToParam Float where
toParam = pack . show
instance ToParam Double where
toParam = pack . show
instance ToParam Bool where
toParam True = "true"
toParam False = "false"
instance ToParam Char where
toParam char = pack [char]
instance ToParam String where
toParam = pack
instance ToParam Text where
toParam = id
instance ToParam Data.Text.Lazy.Text where
toParam = cs
instance ToParam Data.ByteString.ByteString where
toParam = cs
instance ToParam Data.ByteString.Lazy.ByteString where
toParam = cs
-- | -- |
-- Errors used both by "Web.Hikaru.Action" and "Web.Hikaru.Route" -- Errors used both by "Web.Hikaru.Action" and "Web.Hikaru.Route"
-- to report problems with the requests sent by the user. -- to report problems with the requests sent by the user.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment