Implement Read
This commit is contained in:
parent
fe2df6f7d6
commit
fd1ddce73c
2 changed files with 5 additions and 0 deletions
|
@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- CHANGELOG.md
|
- CHANGELOG.md
|
||||||
- Stack integration
|
- Stack integration
|
||||||
- Borsh serialization for `HexString`
|
- Borsh serialization for `HexString`
|
||||||
|
- `Read` implementation for `HexString`
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import qualified Data.Binary as B (Binary, decode, encode)
|
||||||
|
|
||||||
import qualified GHC.Generics as GHC
|
import qualified GHC.Generics as GHC
|
||||||
import qualified Generics.SOP as SOP
|
import qualified Generics.SOP as SOP
|
||||||
|
import Text.Read
|
||||||
|
|
||||||
-- | Represents a Hex string. Guarantees that all characters it contains
|
-- | Represents a Hex string. Guarantees that all characters it contains
|
||||||
-- are valid hex characters.
|
-- are valid hex characters.
|
||||||
|
@ -45,6 +46,9 @@ newtype HexString = HexString
|
||||||
instance Prelude.Show HexString where
|
instance Prelude.Show HexString where
|
||||||
show = T.unpack . toText
|
show = T.unpack . toText
|
||||||
|
|
||||||
|
instance Read HexString where
|
||||||
|
readsPrec _ s = [((fromText . T.pack) s, "")]
|
||||||
|
|
||||||
instance FromJSON HexString where
|
instance FromJSON HexString where
|
||||||
parseJSON = withText "HexString" $ pure . hexString . TE.encodeUtf8
|
parseJSON = withText "HexString" $ pure . hexString . TE.encodeUtf8
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue