View Source Ymlr.Encoder (ymlr v2.0.0)

Encodes data into YAML strings.

Link to this section Summary

Functions

Encodes the given data as YAML string. Raises if it cannot be encoded.

Encodes the given data as YAML string.

Link to this section Types

@type data() :: map() | [data()] | atom() | binary() | number()

Link to this section Functions

@spec to_s!(data()) :: binary()

Encodes the given data as YAML string. Raises if it cannot be encoded.

examples

Examples

iex> Ymlr.Encoder.to_s!(%{})
"{}"

iex> Ymlr.Encoder.to_s!(%{a: 1, b: 2})
"a: 1\nb: 2"

iex> Ymlr.Encoder.to_s!(%{"a" => "a", "b" => :b, "c" => "true", "d" => "100"})
"a: a\nb: b\nc: 'true'\nd: '100'"

iex> Ymlr.Encoder.to_s!({"a", "b"})
** (ArgumentError) The given data {"a", "b"} cannot be converted to YAML.
@spec to_s(data()) :: {:ok, binary()} | {:error, binary()}

Encodes the given data as YAML string.

examples

Examples

iex> Ymlr.Encoder.to_s(%{a: 1, b: 2})
{:ok, "a: 1\nb: 2"}

iex> Ymlr.Encoder.to_s({"a", "b"})
{:error, "The given data {\"a\", \"b\"} cannot be converted to YAML."}