derive-storable 0.3.0.0 → 0.3.1.0
raw patch · 3 files changed
+31/−5 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Foreign.Storable.Generic: getFilling :: (Generic a, GStorable a, GStorable' (Rep a)) => a -> [Filling]
Files
- ChangeLog.md +5/−0
- derive-storable.cabal +3/−3
- src/Foreign/Storable/Generic.hs +23/−2
ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for derive-storable +## 0.3.1.0 -- 2021-04-13++* Added a non-internal getFilling helper [thanks to dpwiz](https://github.com/mkloczko/derive-storable/pull/8).++ ## 0.3.0.0 -- 2020-03-01 * Removed instances module. A breaking change therefore bump to 0.3.
derive-storable.cabal view
@@ -1,7 +1,7 @@ name: derive-storable -version: 0.3.0.0-synopsis: Derive Storable instances with GHC.Generics. +version: 0.3.1.0+synopsis: Derive Storable instances with GHC.Generics. description: Derive Storable instances with GHC.Generics. The derived Storable instances have the same alignment as C structs. @@ -20,7 +20,7 @@ extra-source-files: ChangeLog.md README.md cabal-version: >=1.10-tested-with: GHC==8.0.2, GHC==8.2.2, GHC==8.4.2, GHC==8.6.4, GHC==8.8.1+tested-with: GHC==8.2.2, GHC==8.4.2, GHC==8.6.4, GHC==8.8.1, GHC==8.10.4, GHC==9.0.1, GHC==9.2.1 Flag sumtypes Description: Enable support for non-recursive sum types.
src/Foreign/Storable/Generic.hs view
@@ -17,9 +17,30 @@ {-#LANGUAGE UndecidableInstances #-} -module Foreign.Storable.Generic (GStorable (..), Storable(..)) where+module Foreign.Storable.Generic (GStorable (..), Storable(..), getFilling) where import Foreign.Storable (Storable(..))-import Foreign.Storable.Generic.Internal (GStorable (..))+import GHC.Generics++import Foreign.Storable.Generic.Internal (GStorable (..), GStorable' (..))+import qualified Foreign.Storable.Generic.Tools as Tools++{- | A helper to visualize layout.++>>> data Foo = Foo Word8 Float Word32 Float deriving (Show, Generic, GStorable)+>>> getFilling (Foo 0 0 0 0)+[Size 1,Padding 3,Size 4,Size 4,Size 4]++Nested structures are opaque to their parents:++>>> data Bar = Bar Foo Double Double+>>> getFilling $ Bar (Foo 0 0 0 0) 0 0+[Size 16,Size 8,Size 8]+-}+getFilling :: (Generic a, GStorable a, GStorable' (Rep a)) => a -> [Tools.Filling]+getFilling x = Tools.getFilling $ zip sizes aligns+ where sizes = glistSizeOf' gx+ aligns = glistAlignment' gx+ gx = from x