module Network.Mail.Postie.SessionID
( SessionID,
mkSessionID,
toByteString,
)
where
import Data.ByteString (ByteString)
import Data.Typeable (Typeable)
import Data.UUID (UUID, toASCIIBytes, toString)
import Data.UUID.V4 (nextRandom)
newtype SessionID = SessionID {SessionID -> UUID
toUUID :: UUID}
deriving (SessionID -> SessionID -> Bool
(SessionID -> SessionID -> Bool)
-> (SessionID -> SessionID -> Bool) -> Eq SessionID
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SessionID -> SessionID -> Bool
$c/= :: SessionID -> SessionID -> Bool
== :: SessionID -> SessionID -> Bool
$c== :: SessionID -> SessionID -> Bool
Eq, Eq SessionID
Eq SessionID =>
(SessionID -> SessionID -> Ordering)
-> (SessionID -> SessionID -> Bool)
-> (SessionID -> SessionID -> Bool)
-> (SessionID -> SessionID -> Bool)
-> (SessionID -> SessionID -> Bool)
-> (SessionID -> SessionID -> SessionID)
-> (SessionID -> SessionID -> SessionID)
-> Ord SessionID
SessionID -> SessionID -> Bool
SessionID -> SessionID -> Ordering
SessionID -> SessionID -> SessionID
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
min :: SessionID -> SessionID -> SessionID
$cmin :: SessionID -> SessionID -> SessionID
max :: SessionID -> SessionID -> SessionID
$cmax :: SessionID -> SessionID -> SessionID
>= :: SessionID -> SessionID -> Bool
$c>= :: SessionID -> SessionID -> Bool
> :: SessionID -> SessionID -> Bool
$c> :: SessionID -> SessionID -> Bool
<= :: SessionID -> SessionID -> Bool
$c<= :: SessionID -> SessionID -> Bool
< :: SessionID -> SessionID -> Bool
$c< :: SessionID -> SessionID -> Bool
compare :: SessionID -> SessionID -> Ordering
$ccompare :: SessionID -> SessionID -> Ordering
$cp1Ord :: Eq SessionID
Ord, Typeable)
instance Show SessionID where
show :: SessionID -> String
show = UUID -> String
toString (UUID -> String) -> (SessionID -> UUID) -> SessionID -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SessionID -> UUID
toUUID
mkSessionID :: IO SessionID
mkSessionID :: IO SessionID
mkSessionID = UUID -> SessionID
SessionID (UUID -> SessionID) -> IO UUID -> IO SessionID
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` IO UUID
nextRandom
toByteString :: SessionID -> ByteString
toByteString :: SessionID -> ByteString
toByteString = UUID -> ByteString
toASCIIBytes (UUID -> ByteString)
-> (SessionID -> UUID) -> SessionID -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SessionID -> UUID
toUUID