Maybe combine the struct type and defstruct into one (with a macro)?
It’s been a while since I developed my deftypestruct and I’ve seen someone posting a library doing something very similar here like a week or two ago.
ex (my lib creates {module_name}.t(), but can be made to use a different type name too):
defmodule Person do
deftypestruct %{
name: String.t(),
age: non_neg_integer() | nil,
role: role()
}
end
I also check against nil so unless explicitly permitted (like the age field above) the lib raises.






















