    {- |
    Storable instances for simple wrapped types.

    Example:

    > import qualified Foreign.Storable.Newtype as Store
    >
    > newtype MuLaw = MuLaw {deMuLaw :: Word8}
    >
    > instance Storable MuLaw where
    >    sizeOf = Store.sizeOf deMuLaw
    >    alignment = Store.alignment deMuLaw
    >    peek = Store.peek MuLaw
    >    poke = Store.poke deMuLaw
    -}
    module Foreign.Storable.Newtype where

    import Foreign.Ptr (Ptr, castPtr, )
    import Foreign.Storable (Storable, )
    import qualified Foreign.Storable as Store

    sizeOf :: Storable core => (wrapper -> core) -> wrapper -> Int
    sizeOf :: (wrapper -> core) -> wrapper -> Int
    sizeOf unwrap :: wrapper -> core
    unwrap = core -> Int
    forall a. Storable a => a -> Int
    Store.sizeOf (core -> Int) -> (wrapper -> core) -> wrapper -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . wrapper -> core
    unwrap

    alignment :: Storable core => (wrapper -> core) -> wrapper -> Int
    alignment :: (wrapper -> core) -> wrapper -> Int
    alignment unwrap :: wrapper -> core
    unwrap = core -> Int
    forall a. Storable a => a -> Int
    Store.alignment (core -> Int) -> (wrapper -> core) -> wrapper -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . wrapper -> core
    unwrap

    peek :: Storable core =>
       (core -> wrapper) -> Ptr wrapper -> IO wrapper
    peek :: (core -> wrapper) -> Ptr wrapper -> IO wrapper
    peek wrap :: core -> wrapper
    wrap =
       (core -> wrapper) -> IO core -> IO wrapper
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap core -> wrapper
    wrap (IO core -> IO wrapper)
    -> (Ptr wrapper -> IO core) -> Ptr wrapper -> IO wrapper
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Ptr core -> IO core
    forall a. Storable a => Ptr a -> IO a
    Store.peek (Ptr core -> IO core)
    -> (Ptr wrapper -> Ptr core) -> Ptr wrapper -> IO core
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Ptr wrapper -> Ptr core
    forall a b. Ptr a -> Ptr b
    castPtr

    poke :: Storable core =>
       (wrapper -> core) -> Ptr wrapper -> wrapper -> IO ()
    poke :: (wrapper -> core) -> Ptr wrapper -> wrapper -> IO ()
    poke unwrap :: wrapper -> core
    unwrap ptr :: Ptr wrapper
    ptr =
       Ptr core -> core -> IO ()
    forall a. Storable a => Ptr a -> a -> IO ()
    Store.poke (Ptr wrapper -> Ptr core
    forall a b. Ptr a -> Ptr b
    castPtr Ptr wrapper
    ptr) (core -> IO ()) -> (wrapper -> core) -> wrapper -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . wrapper -> core
    unwrap