make LTS branch pre-releases
[cabal.git] / Cabal-syntax / src / Distribution / Types / AbiHash.hs
bloba1be416c4bae2cd36f7f0f0a95898ddf1d5282ca
1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
3 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
5 module Distribution.Types.AbiHash
6 ( AbiHash
7 , unAbiHash
8 , mkAbiHash
9 ) where
11 import Distribution.Compat.Prelude
12 import Distribution.Utils.ShortText
13 import Prelude ()
15 import qualified Distribution.Compat.CharParsing as P
16 import Distribution.Parsec
17 import Distribution.Pretty
19 import Text.PrettyPrint (text)
21 -- | ABI Hashes
23 -- Use 'mkAbiHash' and 'unAbiHash' to convert from/to a
24 -- 'String'.
26 -- This type is opaque since @Cabal-2.0@
28 -- @since 2.0.0.2
29 newtype AbiHash = AbiHash ShortText
30 deriving (Eq, Show, Read, Generic, Typeable)
32 -- | Convert 'AbiHash' to 'String'
34 -- @since 2.0.0.2
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
43 -- 'AbiHash' is valid
45 -- @since 2.0.0.2
46 mkAbiHash :: String -> AbiHash
47 mkAbiHash = AbiHash . toShortText
49 -- | 'mkAbiHash'
51 -- @since 2.0.0.2
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)