rec_struct
Erlang record to Elixir structure converter. Allows for simple defining of Elixir structures that automatically map to Erlang records imported from a header file.
Installation
The package is available in Hex and can be installed
by adding rec_struct to your list of dependencies in mix.exs:
def deps do
[
{:rec_struct, "~> 0.2.0"}
]
endDocumentation can be generated with ExDoc. The documentation can also be found at https://hexdocs.pm/rec_struct.
Usage
To use record structures first the header file, from which the Erlang records will be imported, must be defined. That is done using the defheader macro:
defheader MyModule, "include/path_to_header/header.hrl", do
(...)
end
This will import the header and use Record.defrecord to define the macros that can be used to build and manipulate records directly in the MyModule.Records module
that will be generated.
With the header imported now each individual record can be imported and mapped to an Elixir structure by using:
defheader TestHeader, "test/test.hrl" do
defrecstruct TestRec, :test_record
defrecstruct OtherTestRec, :other_test_record
end
This will define two structures in TestHeader.Structures.TestRec and TestHeader.Structures.OtherTestRec modules. Additionally two functions will be defined in
TestHeader.Structures:
to_struct/1which transforms an Erlang record (tuple) to the appropriate Elixir structureto_record/1which transforms and Elixir structure into a record.
Please see the documentation for more information and examples.
Note
Currently the defheader and defrectstruct macros only work correctly if RecStruct module is imported!