git-annex/Types/UUID.hs

30 lines
606 B
Haskell
Raw Normal View History

{- git-annex UUID type
-
- Copyright 2011 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Types.UUID where
import qualified Data.Map as M
import qualified Data.UUID as U
import Data.Maybe
-- A UUID is either an arbitrary opaque string, or UUID info may be missing.
data UUID = NoUUID | UUID String
deriving (Eq, Ord, Show, Read)
fromUUID :: UUID -> String
fromUUID (UUID u) = u
fromUUID NoUUID = ""
toUUID :: String -> UUID
toUUID [] = NoUUID
toUUID s = UUID s
isUUID :: String -> Bool
isUUID = isJust . U.fromString
type UUIDMap = M.Map UUID String