Creating a behavior in elixir for an erlang library

Hi

I am using an erlang library(https://github.com/klarna/ponos) in my elixir code. I need to define the callback behavior of erlang library in elixir code. Are there any references to do the same and what is the syntax?

Thanks,
Srikanth V

It’s the same syntax as with an elixir behaviour.

Specifically,

In Elixir, you will use @behaviour behaviour_name attribute to specify that the current module adheres to that behaviour. behaviour_name is an atom, and if it’s an Erlang behaviour, you will need to use their lowecase name, i.e., @behaviour :gen_spider.

For callbacks, you just define the functions normally, just make sure they are public.

Also, as of newer Elixir version, you need to put @impl true before each callback functions to indicate that this is the implementation of the callback.

For a more general documentation, see https://elixir-lang.org/getting-started/typespecs-and-behaviours.html#behaviours

1 Like

Thanks @NobbZ and @sntran