I have this modules where I'm trying to define a struct:
defmodule A do
defmodule B do
defstruct :id, :name
end
end
Why error?
undefined function defstruct/2
Why is this error?
Elixir interprets defstruct :id, :name as calling defstruct with 2 arguments, that's the /2 part in undefined function defstruct/2.
What you want to do is pass a single argument to defstruct, a list of field names:
defmodule A do
defmodule B do
defstruct [:id, :name]
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With