1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
3 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
5 module Distribution
.Types
.AbiHash
11 import Distribution
.Compat
.Prelude
12 import Distribution
.Utils
.ShortText
15 import qualified Distribution
.Compat
.CharParsing
as P
16 import Distribution
.Parsec
17 import Distribution
.Pretty
19 import Text
.PrettyPrint
(text
)
23 -- Use 'mkAbiHash' and 'unAbiHash' to convert from/to a
26 -- This type is opaque since @Cabal-2.0@
29 newtype AbiHash
= AbiHash ShortText
30 deriving (Eq
, Show, Read, Generic
, Typeable
)
32 -- | Convert 'AbiHash' to 'String'
35 unAbiHash
:: AbiHash
-> String
36 unAbiHash
(AbiHash h
) = fromShortText h
38 -- | Construct a 'AbiHash' from a 'String'
40 -- 'mkAbiHash' is the inverse to 'unAbiHash'
42 -- Note: No validations are performed to ensure that the resulting
46 mkAbiHash
:: String -> AbiHash
47 mkAbiHash
= AbiHash
. toShortText
52 instance IsString AbiHash
where
53 fromString
= mkAbiHash
55 instance Binary AbiHash
56 instance Structured AbiHash
57 instance NFData AbiHash
where rnf
= genericRnf
59 instance Pretty AbiHash
where
60 pretty
= text
. unAbiHash
62 instance Parsec AbiHash
where
63 parsec
= fmap mkAbiHash
(P
.munch
isAlphaNum)