curryrs 0.1.1.0 → 0.2.0
raw patch · 6 files changed
+125/−125 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Convert: data ConversionError
- Convert: fromBoolean :: Boolean -> Either ConversionError Bool
- Convert: instance GHC.Classes.Eq Convert.ConversionError
- Convert: instance GHC.Show.Show Convert.ConversionError
- Types: type Boolean = Word8
- Types: type Chr = CChar
- Types: type F32 = CFloat
- Types: type F64 = CDouble
- Types: type I16 = Int16
- Types: type I32 = Int32
- Types: type I64 = Int64
- Types: type I8 = Int8
- Types: type Str = CString
- Types: type U16 = Word16
- Types: type U32 = Word32
- Types: type U64 = Word64
- Types: type U8 = Word8
+ Curryrs.Convert: data ConversionError
+ Curryrs.Convert: fromBoolean :: Boolean -> Either ConversionError Bool
+ Curryrs.Convert: instance GHC.Classes.Eq Curryrs.Convert.ConversionError
+ Curryrs.Convert: instance GHC.Show.Show Curryrs.Convert.ConversionError
+ Curryrs.Types: type Boolean = Word8
+ Curryrs.Types: type Chr = CChar
+ Curryrs.Types: type F32 = CFloat
+ Curryrs.Types: type F64 = CDouble
+ Curryrs.Types: type I16 = Int16
+ Curryrs.Types: type I32 = Int32
+ Curryrs.Types: type I64 = Int64
+ Curryrs.Types: type I8 = Int8
+ Curryrs.Types: type Str = CString
+ Curryrs.Types: type U16 = Word16
+ Curryrs.Types: type U32 = Word32
+ Curryrs.Types: type U64 = Word64
+ Curryrs.Types: type U8 = Word8
Files
- curryrs.cabal +3/−3
- haskell-tests/Test.hs +2/−2
- src/Convert.hs +0/−39
- src/Curryrs/Convert.hs +39/−0
- src/Curryrs/Types.hs +81/−0
- src/Types.hs +0/−81
curryrs.cabal view
@@ -1,5 +1,5 @@ name: curryrs-version: 0.1.1.0+version: 0.2.0 synopsis: Easy to use FFI Bridge for using Rust in Haskell description: Please see README.md for more information on how to use this library. homepage: https://github.com/mgattozzi/curryrs#readme@@ -14,8 +14,8 @@ library hs-source-dirs: src- exposed-modules: Types- , Convert+ exposed-modules: Curryrs.Types+ , Curryrs.Convert build-depends: base >= 4.7 && < 5 , mtl >= 2.2 && < 2.3 default-language: Haskell2010
haskell-tests/Test.hs view
@@ -1,7 +1,7 @@ module Main where -import Types-import Convert+import Curryrs.Types+import Curryrs.Convert import Test.Tasty import Test.Tasty.HUnit
− src/Convert.hs
@@ -1,39 +0,0 @@--- |--- The Convert module contains various functions used for converting--- values to or from their FFI form. It also contains Error types in--- case conversions to not go as planned.-module Convert (- fromBoolean- , ConversionError- ) where--import Types (Boolean)---- |--- This method tries to to turn a number returned--- by FFI into a Bool. It's wrapped in an either--- in case the underlying number representing the Boolean--- is not 0 or 1------ >>> fromBoolean 1--- Right True------ >>> fromBoolean 0--- Right False------ >>> fromBoolean 3--- Left Failed to extract a boolean value in the use of fromBoolean. Number was not 0 or 1-fromBoolean :: Boolean -> Either ConversionError Bool-fromBoolean x = case x of- 0 -> (Right False)- 1 -> (Right True)- _ -> (Left Boolean)---- |--- Error data type for conversions that have failed going to or from--- their FFI form-data ConversionError = Boolean- deriving Eq--instance Show ConversionError where- show Boolean = "Failed to extract a boolean value in the use of fromBoolean. Number was not 0 or 1"
+ src/Curryrs/Convert.hs view
@@ -0,0 +1,39 @@+-- |+-- The Convert module contains various functions used for converting+-- values to or from their FFI form. It also contains Error types in+-- case conversions to not go as planned.+module Curryrs.Convert (+ fromBoolean+ , ConversionError+ ) where++import Curryrs.Types (Boolean)++-- |+-- This method tries to to turn a number returned+-- by FFI into a Bool. It's wrapped in an either+-- in case the underlying number representing the Boolean+-- is not 0 or 1+--+-- >>> fromBoolean 1+-- Right True+--+-- >>> fromBoolean 0+-- Right False+--+-- >>> fromBoolean 3+-- Left Failed to extract a boolean value in the use of fromBoolean. Number was not 0 or 1+fromBoolean :: Boolean -> Either ConversionError Bool+fromBoolean x = case x of+ 0 -> (Right False)+ 1 -> (Right True)+ _ -> (Left Boolean)++-- |+-- Error data type for conversions that have failed going to or from+-- their FFI form+data ConversionError = Boolean+ deriving Eq++instance Show ConversionError where+ show Boolean = "Failed to extract a boolean value in the use of fromBoolean. Number was not 0 or 1"
+ src/Curryrs/Types.hs view
@@ -0,0 +1,81 @@+-- |+-- Definitions of each FFI type that can be used in Rust. These are+-- standardized accross the Rust and Haskell Curryrs library for easy+-- translation of function headers between the two.+module Curryrs.Types (+ module Foreign.C.Types+ , module Foreign.C.String+ , Chr+ , Str+ , U8+ , U16+ , U32+ , U64+ , I8+ , I16+ , I32+ , I64+ , F32+ , F64+ , Boolean+ ) where++import Data.Int+import Data.Word+import Foreign.C.Types+import Foreign.C.String++-- We are only defining types that map to Rust types here+-- We don't need the full array of C types in Rust++-- |+-- Used to represent Char in both languages+type Chr = CChar++-- |+-- Used to represent Strings in both languages+type Str = CString++-- |+-- Used to represent 8 bit unsigned numbers in both languages+type U8 = Word8++-- |+-- Used to represent 16 bit unsigned numbers in both languages+type U16 = Word16++-- |+-- Used to represent 32 bit unsigned numbers in both languages+type U32 = Word32++-- |+-- Used to represent 64 bit unsigned numbers in both languages+type U64 = Word64++-- |+-- Used to represent 8 bit signed numbers in both languages+type I8 = Int8++-- |+-- Used to represent 16 bit signed numbers in both languages+type I16 = Int16++-- |+-- Used to represent 32 bit signed numbers in both languages+type I32 = Int32++-- |+-- Used to represent 64 bit signed numbers in both languages+type I64 = Int64++-- |+-- Used to represent 32 bit floating point numbers in both languages+type F32 = CFloat++-- |+-- Used to represent 64 bit floating point numbers in both languages+type F64 = CDouble++-- |+-- Used to represent Booleans in both languages+type Boolean = Word8
− src/Types.hs
@@ -1,81 +0,0 @@--- |--- Definitions of each FFI type that can be used in Rust. These are--- standardized accross the Rust and Haskell Curryrs library for easy--- translation of function headers between the two.-module Types (- module Foreign.C.Types- , module Foreign.C.String- , Chr- , Str- , U8- , U16- , U32- , U64- , I8- , I16- , I32- , I64- , F32- , F64- , Boolean- ) where--import Data.Int-import Data.Word-import Foreign.C.Types-import Foreign.C.String---- We are only defining types that map to Rust types here--- We don't need the full array of C types in Rust---- |--- Used to represent Char in both languages-type Chr = CChar---- |--- Used to represent Strings in both languages-type Str = CString---- |--- Used to represent 8 bit unsigned numbers in both languages-type U8 = Word8---- |--- Used to represent 16 bit unsigned numbers in both languages-type U16 = Word16---- |--- Used to represent 32 bit unsigned numbers in both languages-type U32 = Word32---- |--- Used to represent 64 bit unsigned numbers in both languages-type U64 = Word64---- |--- Used to represent 8 bit signed numbers in both languages-type I8 = Int8---- |--- Used to represent 16 bit signed numbers in both languages-type I16 = Int16---- |--- Used to represent 32 bit signed numbers in both languages-type I32 = Int32---- |--- Used to represent 64 bit signed numbers in both languages-type I64 = Int64---- |--- Used to represent 32 bit floating point numbers in both languages-type F32 = CFloat---- |--- Used to represent 64 bit floating point numbers in both languages-type F64 = CDouble---- |--- Used to represent Booleans in both languages-type Boolean = Word8