Crate foreignc

Source
Expand description

§Foreignc

Foreignc is a framework for auto generating a safe ffi abi for rust methods. The main advantage if foreignc is that allows for easy deplayment and maintenance of safe ffi abi. The crate is made up of two parts.

  • Macros for auto generating ffi abis and cleanup methods
  • Functions for auto generate the recieving end of the ffi abi
    • Currently only python is supported

§Templating

Using the feature ‘template’ it is possible to auto generate the recieving side of the ffi. This will also add two new functions get_package_dir and get_parsed_dir. Both functions return a representation of the current ffi api

§Default types

§Primititve types

The following primitive types are supported:

  • bool
  • ()
  • i8, i16, i32, i64
  • u8, u16, u32, u64
  • f32, f64
  • &str (will be converted to a CString)

§Other types

The following other types are soppurted:

  • Result (will be converted to a CResult)
  • Option (will be converted to a COption)
  • String (will be converted to a CString)

§Custom Structs

Custom types can be implemented either by using the IntoFFi, FromFFi trait or the Boxed, Json macro.

§Safety

As a rule of thumb, all allocated memory needs too be unallocated by the creator. This is also the basis for generate_free_methods that creates frunctions for freeing memory allocated by structures made by foreignc The following functions are made

  • free_string(ptr: *mut CString)
  • free_coption(ptr: *mut COption)
  • free_cresult(ptr: *mut CResult)

Boxed structs will auto generate a free method using the following convention free_{to_snake_case(struct name)}

For more information see the ![git repository]

Macros§

generate_free_methods

Structs§

CResult
A ffi safe representation of a result
CString
A type representing an owned, C-compatible, nul-terminated string with no nul bytes in the middle.
FFiError
Representation of a error during traversal of the ffi barrier. This can be caused from everything from null pointer exceptions to the program panicing
FFiResultWrap

Enums§

c_void
Equivalent to C’s void type when used as a pointer.

Traits§

FromFFi
IntoFFi
Convert a rust value into ffi safe counter part

Functions§

free_libc

Type Aliases§

FFiResult

Attribute Macros§

with_abi

Derive Macros§

Boxed
Json