Ecto.Type.cast

You're seeing just the callback cast, go back to Ecto.Type module for more information.

Specs

cast(term()) :: {:ok, term()} | :error | {:error, keyword()}

Casts the given input to the custom type.

This callback is called on external input and can return any type, as long as the dump/1 function is able to convert the returned value into an Ecto native type. There are two situations where this callback is called:

  1. When casting values by Ecto.Changeset
  2. When passing arguments to Ecto.Query

You can return :error if the given term cannot be cast. A default error message of "is invalid" will be added to the changeset.

You may also return {:error, keyword()} to customize the changeset error message and its metadata. Passing a :message key, will override the default message. It is not possible to override the :type key.

For {:array, CustomType} or {:map, CustomType} the returned keyword list will be erased and the default error will be shown.