Conform.Type behaviour

Defines the behaviour for custom types.

Callbacks

parse_datatype/2

Specs:

  • parse_datatype(atom, term) :: {:ok, term} | {:error, term}

By default conform reads values as string. Implement your own conversion using this callback. If you implement your own conversion, you must return either {:ok, val} | {:error, reason}

to_doc/1

Specs:

Return a string to produce documentation for the given type based on it’s valid values (if specified). Return false if you wish to instead use the documentation specified in the schema.

translate/3

Specs:

  • translate(mapping :: term, value :: term, acc :: [term]) :: term | {:error, term}

Translate an input value based on the provided mapping. Should return the translated value or {:error, reason}