- , etagToken :: String
- } deriving (Eq)
-
-instance Show ETag where
- show (ETag isWeak token) = (if isWeak then
- "W/"
- else
- "")
- ++
- quoteStr token
-
--- |This is equivalent to @'ETag' False@. If you want to generate
--- an ETag from a file, try using
+ , etagToken ∷ !Ascii
+ } deriving (Eq, Show)
+
+-- |Convert an 'ETag' to an 'AsciiBuilder'.
+printETag ∷ ETag → AsciiBuilder
+{-# INLINEABLE printETag #-}
+printETag et
+ = ( if etagIsWeak et then
+ A.toAsciiBuilder "W/"
+ else
+ (∅)
+ )
+ ⊕
+ quoteStr (etagToken et)
+
+-- |Parse 'Etag' from an 'Ascii'. This functions throws an exception
+-- for parse error.
+parseETag ∷ Ascii → ETag
+{-# INLINEABLE parseETag #-}
+parseETag str
+ = case parseOnly (finishOff eTag) $ A.toByteString str of
+ Right et → et
+ Left err → error ("unparsable ETag: " ⧺ A.toString str ⧺ ": " ⧺ err)
+
+-- |This is equivalent to @'ETag' 'False'@. If you want to generate an
+-- ETag from a file, try using