--- |Parse 'Etag' from an 'Ascii'. This functions throws an exception
--- for parse error.
-parseETag ∷ Ascii → ETag
-{-# INLINEABLE parseETag #-}
-parseETag str
- = case parseOnly p $ A.toByteString str of
- Right et → et
- Left err → error ("unparsable ETag: " ⧺ A.toString str ⧺ ": " ⧺ err)
- where
- p ∷ Parser ETag
- {-# INLINE p #-}
- p = do et ← eTagP
- endOfInput
- return et
+instance ConvertSuccess ETag Ascii where
+ {-# INLINE convertSuccess #-}
+ convertSuccess = convertSuccessVia ((⊥) ∷ AsciiBuilder)
+
+instance ConvertSuccess ETag AsciiBuilder where
+ {-# INLINE convertSuccess #-}
+ convertSuccess (ETag {..})
+ = ( if etagIsWeak then
+ cs ("W/" ∷ Ascii)
+ else
+ (∅)
+ )
+ ⊕
+ quoteStr etagToken
+
+deriveAttempts [ ([t| ETag |], [t| Ascii |])
+ , ([t| ETag |], [t| AsciiBuilder |])
+ ]