File: eetcd_data_coercion.erl

package info (click to toggle)
rabbitmq-server 3.8.9-3%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 39,392 kB
  • sloc: erlang: 170,802; javascript: 18,467; sh: 3,482; makefile: 2,293; python: 1,990; xml: 623; cs: 368; java: 319; ruby: 212; php: 100; perl: 63; awk: 13
file content (17 lines) | stat: -rw-r--r-- 752 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-module(eetcd_data_coercion).

%% API
-export([to_list/1, to_binary/1]).

-spec to_list(Val :: integer() | list() | binary() | atom() | map()) -> list().
to_list(Val) when is_list(Val)    -> Val;
to_list(Val) when is_map(Val)     -> maps:to_list(Val);
to_list(Val) when is_atom(Val)    -> atom_to_list(Val);
to_list(Val) when is_binary(Val)  -> binary_to_list(Val);
to_list(Val) when is_integer(Val) -> integer_to_list(Val).

-spec to_binary(Val :: binary() | list() | atom() | integer()) -> binary().
to_binary(Val) when is_list(Val)    -> list_to_binary(Val);
to_binary(Val) when is_atom(Val)    -> atom_to_binary(Val, utf8);
to_binary(Val) when is_integer(Val) -> integer_to_binary(Val);
to_binary(Val)                      -> Val.