View Source TypedStructor.Definer.Defrecord (TypedStructor v0.5.0)

A definer to define record macors and a type for a given definition.

Additional options for typed_structor

  • :record_name(required) - the name of the record, it must be provided.
  • :record_tag - if set, the record will be tagged with the given value. Defaults to nil.
  • :define_record - if false, the type will be defined, but the record will not be defined. Defaults to true.

Usage

defmodule MyRecord do
  use TypedStructor

  typed_structor definer: :defrecord, record_name: :user, record_tag: User, define_recrod: true do
    field :name, String.t(), enforce: true
    field :age, pos_integer(), enforce: true
  end
end

The above code is equivalent to:

defmodule MyRecord do
  require Record

  @type t() :: {User, name :: String.t(), age :: pos_integer()}

  Record.defrecord(:user, User, [:name, :age])
end

Summary

Functions

Defines an exception and a type for a given definition.

Functions

Link to this macro

define(definition)

View Source (macro)

Defines an exception and a type for a given definition.