View Source Want.Atom (want v1.17.1)

Performs type conversions to atom values.

Summary

Functions

Cast a value to an atom.

Callback implementation for Want.Type.cast/2.

Types

@type result() :: {:ok, atom()} | {:error, binary()}

Functions

@spec cast(value :: any()) :: result()

Cast a value to an atom.

Options

  • :exists - If true, only convert to an atom if a matching atom already exists.

Examples

iex> Want.Atom.cast("hello")
{:ok, :hello}

iex> Want.Atom.cast(1.0)
{:ok, :'1.0'}

iex> Want.Atom.cast({:a, :b})
{:error, "Failed to convert value {:a, :b} to atom."}

iex> Want.Atom.cast("10", exists: true)
{:error, "An atom matching the given value does not exist."}
@spec cast(value :: any(), opts :: Keyword.t()) :: result()

Callback implementation for Want.Type.cast/2.