Hello, I’m trying to write a specific implementation into the using macro, I have this module :
defmodule Mizur.Implementation do
defmacro __using__(_opts) do
quote do
IO.inspect "test"
defimpl String.Chars, for: __MODULE__.Type do
def to_string(element) do
"test" # It is just a test =)
end
end
end
end
end
And the global module :
defmodule Mizur do
@moduledoc """
**Mizur** is a tool to simplify the management, conversions
and mapping of units.
The manipulation of units of measurement try (at best)
to be typesafe.
"""
defmacro __using__(_opts) do
quote do
use Mizur.System
use Mizur.Implementation
use Mizur.Api
end
end
end
My goal is to write “specifics” to_string implementation for the structs generated in MODULE and MODULE.Type. But when I try this code (and IO.inspect “#{an_expression_in_the_type_of__MODULE__.Type”) I have this two errors :
warning: the String.Chars protocol has already been consolidated, an implementation for MizurTest.Length.Type has no effect
test/mizur_test.exs:8
test test inspection (MizurTest)
test/mizur_test.exs:168
** (Protocol.UndefinedError) protocol String.Chars not implemented for %MizurTest.Chrono.Type{base: 1, from_basis: #Functio
n<7.77242409/1 in MizurTest.Chrono.sec/0>, name: :sec, to_basis: #Function<8.77242409/1 in MizurTest.Chrono.sec/0>}
Thanks a lot for your feedback.