Giter VIP home page Giter VIP logo

rec_struct's Introduction

rec_struct

Build Status Hex.pm Version

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"}
  ]
end

Documentation 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/1 which transforms an Erlang record (tuple) to the appropriate Elixir structure
  • to_record/1 which 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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.