tyyppi v0.1.0 Tyyppi.Struct View Source
Creates the typed struct with spec bound to each field.
Usage:
See Tyyppi.Example
for the example of why and how to use Tyyppi.Struct
.
Example:
iex> defmodule MyStruct do
...> @type my_type :: :ok | {:error, term()}
...> Tyyppi.Struct.defstruct foo: atom(), bar: GenServer.on_start(), baz: my_type()
...> end
iex> types = MyStruct.types()
...> types[:foo]
%Tyyppi.T{
definition: {:type, 0, :atom, []},
module: nil,
name: nil,
params: [],
source: nil,
type: :built_in
}
...> types[:baz]
%Tyyppi.T{
definition: {:type, 0, :union, [
{:atom, 0, :ok},
{:type, 0, :tuple, [
{:atom, 0, :error}, {:type, 0, :term, []}]}]},
module: Test.Tyyppi.Struct.MyStruct,
name: :my_type,
params: [],
quoted: {{:., [], [Test.Tyyppi.Struct.MyStruct, :my_type]}, [], []},
source: :user_type,
type: :type
}