{-# LANGUAGE DeriveAnyClass #-}
{-|
Description : Derived path output names
-}

module System.Nix.OutputName
  ( OutputName(..)
  , mkOutputName
  -- * Re-exports
  , System.Nix.StorePath.InvalidNameError(..)
  , System.Nix.StorePath.parseNameText
  ) where

import Data.Hashable (Hashable)
import Data.Text (Text)
import GHC.Generics (Generic)
import System.Nix.StorePath (InvalidNameError)

import qualified System.Nix.StorePath

-- | Name of the derived path output
-- Typically used for "dev", "doc" sub-outputs
newtype OutputName = OutputName
  { -- | Extract the contents of the name.
    OutputName -> Text
unOutputName :: Text
  } deriving (OutputName -> OutputName -> Bool
(OutputName -> OutputName -> Bool)
-> (OutputName -> OutputName -> Bool) -> Eq OutputName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OutputName -> OutputName -> Bool
== :: OutputName -> OutputName -> Bool
$c/= :: OutputName -> OutputName -> Bool
/= :: OutputName -> OutputName -> Bool
Eq, (forall x. OutputName -> Rep OutputName x)
-> (forall x. Rep OutputName x -> OutputName) -> Generic OutputName
forall x. Rep OutputName x -> OutputName
forall x. OutputName -> Rep OutputName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. OutputName -> Rep OutputName x
from :: forall x. OutputName -> Rep OutputName x
$cto :: forall x. Rep OutputName x -> OutputName
to :: forall x. Rep OutputName x -> OutputName
Generic, Eq OutputName
Eq OutputName =>
(Int -> OutputName -> Int)
-> (OutputName -> Int) -> Hashable OutputName
Int -> OutputName -> Int
OutputName -> Int
forall a. Eq a => (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> OutputName -> Int
hashWithSalt :: Int -> OutputName -> Int
$chash :: OutputName -> Int
hash :: OutputName -> Int
Hashable, Eq OutputName
Eq OutputName =>
(OutputName -> OutputName -> Ordering)
-> (OutputName -> OutputName -> Bool)
-> (OutputName -> OutputName -> Bool)
-> (OutputName -> OutputName -> Bool)
-> (OutputName -> OutputName -> Bool)
-> (OutputName -> OutputName -> OutputName)
-> (OutputName -> OutputName -> OutputName)
-> Ord OutputName
OutputName -> OutputName -> Bool
OutputName -> OutputName -> Ordering
OutputName -> OutputName -> OutputName
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: OutputName -> OutputName -> Ordering
compare :: OutputName -> OutputName -> Ordering
$c< :: OutputName -> OutputName -> Bool
< :: OutputName -> OutputName -> Bool
$c<= :: OutputName -> OutputName -> Bool
<= :: OutputName -> OutputName -> Bool
$c> :: OutputName -> OutputName -> Bool
> :: OutputName -> OutputName -> Bool
$c>= :: OutputName -> OutputName -> Bool
>= :: OutputName -> OutputName -> Bool
$cmax :: OutputName -> OutputName -> OutputName
max :: OutputName -> OutputName -> OutputName
$cmin :: OutputName -> OutputName -> OutputName
min :: OutputName -> OutputName -> OutputName
Ord, Int -> OutputName -> ShowS
[OutputName] -> ShowS
OutputName -> String
(Int -> OutputName -> ShowS)
-> (OutputName -> String)
-> ([OutputName] -> ShowS)
-> Show OutputName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OutputName -> ShowS
showsPrec :: Int -> OutputName -> ShowS
$cshow :: OutputName -> String
show :: OutputName -> String
$cshowList :: [OutputName] -> ShowS
showList :: [OutputName] -> ShowS
Show)

mkOutputName :: Text -> Either InvalidNameError OutputName
mkOutputName :: Text -> Either InvalidNameError OutputName
mkOutputName = (Text -> OutputName)
-> Either InvalidNameError Text
-> Either InvalidNameError OutputName
forall a b.
(a -> b) -> Either InvalidNameError a -> Either InvalidNameError b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> OutputName
OutputName (Either InvalidNameError Text
 -> Either InvalidNameError OutputName)
-> (Text -> Either InvalidNameError Text)
-> Text
-> Either InvalidNameError OutputName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Either InvalidNameError Text
System.Nix.StorePath.parseNameText