{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Distribution.Types.AbiHash
  ( AbiHash, unAbiHash, mkAbiHash
  ) where

import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Utils.ShortText

import qualified Distribution.Compat.CharParsing as P
import Distribution.Pretty
import Distribution.Parsec

import Text.PrettyPrint (text)

-- | ABI Hashes
--
-- Use 'mkAbiHash' and 'unAbiHash' to convert from/to a
-- 'String'.
--
-- This type is opaque since @Cabal-2.0@
--
-- @since 2.0.0.2
newtype AbiHash = AbiHash ShortText
    deriving (AbiHash -> AbiHash -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AbiHash -> AbiHash -> Bool
$c/= :: AbiHash -> AbiHash -> Bool
== :: AbiHash -> AbiHash -> Bool
$c== :: AbiHash -> AbiHash -> Bool
Eq, Int -> AbiHash -> ShowS
[AbiHash] -> ShowS
AbiHash -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AbiHash] -> ShowS
$cshowList :: [AbiHash] -> ShowS
show :: AbiHash -> String
$cshow :: AbiHash -> String
showsPrec :: Int -> AbiHash -> ShowS
$cshowsPrec :: Int -> AbiHash -> ShowS
Show, ReadPrec [AbiHash]
ReadPrec AbiHash
Int -> ReadS AbiHash
ReadS [AbiHash]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AbiHash]
$creadListPrec :: ReadPrec [AbiHash]
readPrec :: ReadPrec AbiHash
$creadPrec :: ReadPrec AbiHash
readList :: ReadS [AbiHash]
$creadList :: ReadS [AbiHash]
readsPrec :: Int -> ReadS AbiHash
$creadsPrec :: Int -> ReadS AbiHash
Read, forall x. Rep AbiHash x -> AbiHash
forall x. AbiHash -> Rep AbiHash x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AbiHash x -> AbiHash
$cfrom :: forall x. AbiHash -> Rep AbiHash x
Generic, Typeable)

-- | Convert 'AbiHash' to 'String'
--
-- @since 2.0.0.2
unAbiHash :: AbiHash -> String
unAbiHash :: AbiHash -> String
unAbiHash (AbiHash ShortText
h) = ShortText -> String
fromShortText ShortText
h

-- | Construct a 'AbiHash' from a 'String'
--
-- 'mkAbiHash' is the inverse to 'unAbiHash'
--
-- Note: No validations are performed to ensure that the resulting
-- 'AbiHash' is valid
--
-- @since 2.0.0.2
mkAbiHash :: String -> AbiHash
mkAbiHash :: String -> AbiHash
mkAbiHash = ShortText -> AbiHash
AbiHash forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShortText
toShortText

-- | 'mkAbiHash'
--
-- @since 2.0.0.2
instance IsString AbiHash where
    fromString :: String -> AbiHash
fromString = String -> AbiHash
mkAbiHash

instance Binary AbiHash
instance Structured AbiHash
instance NFData AbiHash where rnf :: AbiHash -> ()
rnf = forall a. (Generic a, GNFData (Rep a)) => a -> ()
genericRnf

instance Pretty AbiHash where
    pretty :: AbiHash -> Doc
pretty = String -> Doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. AbiHash -> String
unAbiHash

instance Parsec AbiHash where
    parsec :: forall (m :: * -> *). CabalParsing m => m AbiHash
parsec = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> AbiHash
mkAbiHash (forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m String
P.munch Char -> Bool
isAlphaNum)