Nvir.Cast (Nvir v0.11.0)

View Source

Collection of casters for environment variables.

Summary

Functions

Casts an environment variable to the desired type.

Types

caster()

@type caster() ::
  :string
  | :string?
  | :string!
  | :atom
  | :atom?
  | :atom!
  | :existing_atom
  | :existing_atom?
  | :existing_atom!
  | :boolean
  | :boolean!
  | :boolean?
  | :integer!
  | :integer?
  | :integer
  | :float!
  | :float?
  | :float
  | (term() -> result())

result()

@type result() ::
  {:ok, term()} | {:error, String.t()} | {:error, :empty} | {:error, :bad_cast}

Functions

cast(value, caster)

@spec cast(term(), caster()) :: result()
@spec cast(String.t(), caster()) :: result()

Casts an environment variable to the desired type.

Environment variables are always defined as a string. Thus, the cast/2 function will only work with strings as it's first argument.

Please refer to the "Available Casters" of the README for a detailed explanation of all casters.