| Copyright | (C) 2016-2026 David M. Johnson |
|---|---|
| License | BSD3-style (see the file LICENSE) |
| Maintainer | David M. Johnson <code@dmj.io> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Miso.UUID
Description
Overview
Miso.UUID provides a UUID type, as defined in
RFC 4122, backed by a
MisoString. Its API mirrors Data.UUID from the
uuid package.
New v4 UUIDs are generated with the browser's
crypto.randomUUID().
Parsing accepts the canonical 8-4-4-4-12 hexadecimal form, in either
case, and normalizes it to lowercase.
Quick start
import Miso.UUID (tUUID) import qualified Miso.UUID as UUID -- Generate a fresh identifier freshId :: IOUUIDfreshId = UUID.nextRandom-- Parse one parsed :: MaybeUUIDparsed = UUID.fromString"550e8400-e29b-41d4-a716-446655440000" -- Check for the nil UUID isUnset ::UUID-> Bool isUnset = UUID.null
Instances
UUID can be converted to and from MisoString, JSON,
JSVal, and used as a route capture with Miso.Router.
Its Show and Read instances use the unquoted 8-4-4-4-12 form,
like Data.UUID.
Synopsis
- data UUID
- toString :: UUID -> String
- fromString :: String -> Maybe UUID
- toText :: UUID -> Text
- fromText :: Text -> Maybe UUID
- toASCIIBytes :: UUID -> ByteString
- fromASCIIBytes :: ByteString -> Maybe UUID
- toLazyASCIIBytes :: UUID -> ByteString
- fromLazyASCIIBytes :: ByteString -> Maybe UUID
- toByteString :: UUID -> ByteString
- fromByteString :: ByteString -> Maybe UUID
- toWords :: UUID -> (Word32, Word32, Word32, Word32)
- fromWords :: Word32 -> Word32 -> Word32 -> Word32 -> UUID
- toWords64 :: UUID -> (Word64, Word64)
- fromWords64 :: Word64 -> Word64 -> UUID
- null :: UUID -> Bool
- nil :: UUID
- nextRandom :: IO UUID
Types
A universally unique identifier, as defined in RFC 4122.
Instances
| Eq UUID Source # | |
| Ord UUID Source # | |
| Read UUID Source # | |
| Show UUID Source # | |
| FromJSVal UUID Source # | |
| ToJSVal UUID Source # | |
| FromJSON UUID Source # | |
| ToJSON UUID Source # | |
| Router UUID Source # | |
Defined in Miso.UUID | |
| FromMisoString UUID Source # | |
Defined in Miso.UUID Methods fromMisoStringEither :: MisoString -> Either String UUID Source # | |
| ToMisoString UUID Source # | |
Defined in Miso.UUID Methods toMisoString :: UUID -> MisoString Source # | |
String conversion
toASCIIBytes :: UUID -> ByteString Source #
Like toString, but to an ASCII-encoded strict ByteString.
fromASCIIBytes :: ByteString -> Maybe UUID Source #
Like fromString, but from an ASCII-encoded strict ByteString.
toLazyASCIIBytes :: UUID -> ByteString Source #
Like toString, but to an ASCII-encoded lazy ByteString.
fromLazyASCIIBytes :: ByteString -> Maybe UUID Source #
Like fromString, but from an ASCII-encoded lazy ByteString.
Binary conversion
toByteString :: UUID -> ByteString Source #
Encode a UUID as 16 bytes, in network byte order.
fromByteString :: ByteString -> Maybe UUID Source #
toWords :: UUID -> (Word32, Word32, Word32, Word32) Source #
Convert a UUID to four 32-bit words, most significant first.
fromWords :: Word32 -> Word32 -> Word32 -> Word32 -> UUID Source #
Build a UUID from four 32-bit words, most significant first.
toWords64 :: UUID -> (Word64, Word64) Source #
Convert a UUID to two 64-bit words, most significant first.
fromWords64 :: Word64 -> Word64 -> UUID Source #
Build a UUID from two 64-bit words, most significant first.