BehavesLike
Turns a module's specs into callbacks.
Lets you state that a module behaves like another, without writing behaviour callbacks.
For example:
defmodule API do
use BehavesLike
@spec get(binary()) :: {:ok, any()} | {:error, any()}
def get(id) do
Backend.get(id)
end
end
defmodule Backend do
@behaviour API
@impl true
def get(id) do
database().get(id)
end
endInstallation
From Hex:
def deps do
[
{:behaves_like, "~> 0.1.0"}
]
endUsage
Just add use BehavesLike to your module, then you can use the standard @behaviour attribute in other modules to refer to it.