View Source Want.Atom (want v2.0.0)
Performs type conversions to atom values.
Summary
Types
Functions
Cast a value to an atom.
Options
:exists- If true, only convert to an atom if a matching atom already exists.
Atom exhaustion
Without
exists: true, this function callsString.to_atom/1, which creates a new atom that is never garbage collected. Avoid calling this on untrusted external input. Preferexists: trueorWant.Enumwhen the set of valid atoms is known.
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."}
Callback implementation for Want.Type.cast/2.