want v1.1.1 Want.String

Manages conversions to and from strings.

Link to this section Summary

Functions

Casts a given value to a string.

Callback implementation for Want.Type.cast/2.

Link to this section Types

Link to this type

result()

result() :: {:ok, binary()} | {:error, binary()}

Link to this section Functions

Link to this function

cast(value)

cast(value :: any()) :: result()

Casts a given value to a string.

Options

  • :max - Maximum allowable string length.
  • :min - Minimum allowable string length.
  • ':decode' - Currently only supports :uri; runs URI.decode on the input value
  • :matches - The resulting string must match the given regex.

Examples

iex> Want.String.cast(1)

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

iex> Want.String.cast(:hello, max: 3)

iex> Want.String.cast(:a, min: 3)

iex> Want.String.cast("hello%20world", decode: :uri)

iex> Want.String.cast(:a, matches: ~r/a/)

Link to this function

cast(value, opts)

cast(value :: any(), opts :: Keyword.t()) :: result()

Callback implementation for Want.Type.cast/2.